Skip to content

Commit

Permalink
feat: adding interfaces for SocketFactory to use so it is easier to g…
Browse files Browse the repository at this point in the history
…et/set address and port (#996)

Allows Address and Port to be set without knowing the type of SocketFactory being used
  • Loading branch information
James-Frowen committed Nov 29, 2021
1 parent 0d6d34b commit e969e6d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Assets/Mirage/Runtime/SocketLayer/SocketFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

namespace Mirage.SocketLayer
{
/// <summary>
/// Can be added to SocketFactory that have an Address Setting
/// </summary>
public interface IHasAddress
{
string Address { get; set; }
}

/// <summary>
/// Can be added to SocketFactory that have a Port Setting
/// </summary>
public interface IHasPort
{
int Port { get; set; }
}

/// <summary>
/// Creates an instance of <see cref="ISocket"/>
/// </summary>
Expand Down
13 changes: 12 additions & 1 deletion Assets/Mirage/Runtime/Sockets/Udp/UdpSocketFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Mirage.Sockets.Udp
{
public enum SocketLib { Automatic, Native, Managed };

public sealed class UdpSocketFactory : SocketFactory
public sealed class UdpSocketFactory : SocketFactory, IHasAddress, IHasPort
{
public string Address = "localhost";
public ushort Port = 7777;
Expand All @@ -22,6 +22,17 @@ public sealed class UdpSocketFactory : SocketFactory

bool useNanoSocket => SocketLib == SocketLib.Native || (SocketLib == SocketLib.Automatic && IsDesktop);

string IHasAddress.Address
{
get => Address;
set => Address = value;
}
int IHasPort.Port
{
get => Port;
set => Port = checked((ushort)value);
}

static int initCount;

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
Expand Down

0 comments on commit e969e6d

Please sign in to comment.