Skip to content

revert: Add NetworkAddress and NetworkPort properties to Transport #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MLAPI.Transports.Tasks;

namespace MLAPI.Transports.Multiplex
Expand Down Expand Up @@ -54,21 +53,6 @@ public enum ConnectionIdSpreadMethod

private byte m_LastProcessedTransportIndex;

/// <inheritdoc />
public override string NetworkAddress
{
get => Transports.Any() ? Transports.First().NetworkAddress : default;
set => Array.ForEach(Transports, t => t.NetworkAddress = value);
}

/// <inheritdoc />
public override ushort NetworkPort
{
get => Transports.Any() ? Transports.First().NetworkPort : default;
set => Array.ForEach(Transports, t => t.NetworkPort = value);
}


public override bool IsSupported => true;

public override void DisconnectLocalClient()
Expand Down Expand Up @@ -343,4 +327,4 @@ public byte GetFirstSupportedTransportIndex()

#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
}
}
13 changes: 0 additions & 13 deletions com.unity.multiplayer.mlapi/Runtime/Transports/NetworkTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ public abstract class NetworkTransport : MonoBehaviour
/// </summary>
public abstract ulong ServerClientId { get; }

/// <summary>
/// Gets or sets the IP address the client uses to connect to the server.
/// For transports which don't use an IP address to connect this property is used to pass a transport specific connection identifier such as a room name.
/// </summary>
public abstract string NetworkAddress { get; set; }

/// <summary>
/// Gets or sets the port this transport should use for networking.
/// In server/host mode this is the port on which the server is exposed.
/// In client mode this is the port
/// </summary>
public abstract ushort NetworkPort { get; set; }

/// <summary>
/// Gets a value indicating whether this <see cref="T:MLAPI.Transports.Transport"/> is supported in the current runtime context.
/// This is used by multiplex adapters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using MLAPI.Logging;
using MLAPI.Profiling;
using MLAPI.Transports.Tasks;
using UnityEngine;
using UnityEngine.Networking;

namespace MLAPI.Transports.UNET
Expand All @@ -27,10 +26,8 @@ public enum SendMode
public int MaxConnections = 100;
public int MaxSentMessageQueueSize = 128;

[SerializeField]
string m_ConnectAddress = "127.0.0.1";
[SerializeField]
ushort m_ConnectPort = 7777;
public string ConnectAddress = "127.0.0.1";
public int ConnectPort = 7777;
public int ServerListenPort = 7777;
public int ServerWebsocketListenPort = 8887;
public bool SupportWebsocket = false;
Expand Down Expand Up @@ -67,12 +64,6 @@ public enum SendMode
private SocketTask m_ConnectTask;
public override ulong ServerClientId => GetMLAPIClientId(0, 0, true);

/// <inheritdoc />
public override string NetworkAddress { get { return m_ConnectAddress; } set { m_ConnectAddress = value; } }

/// <inheritdoc />
public override ushort NetworkPort { get { return m_ConnectPort; } set { m_ConnectPort = value; } }

protected void LateUpdate()
{
if (UnityEngine.Networking.NetworkTransport.IsStarted && MessageSendMode == SendMode.Queued)
Expand Down Expand Up @@ -152,6 +143,7 @@ public override void Send(ulong clientId, ArraySegment<byte> data, NetworkChanne
}
}


public void SendQueued(ulong clientId)
{
if (ProfilerEnabled)
Expand All @@ -169,11 +161,9 @@ public override NetworkEvent PollEvent(out ulong clientId, out NetworkChannel ne
var eventType = RelayTransport.Receive(out int hostId, out int connectionId, out int channelId, m_MessageBuffer, m_MessageBuffer.Length, out int receivedSize, out byte error);

clientId = GetMLAPIClientId((byte)hostId, (ushort)connectionId, false);

receiveTime = UnityEngine.Time.realtimeSinceStartup;

var networkError = (NetworkError)error;

if (networkError == NetworkError.MessageToLong)
{
byte[] tempBuffer;
Expand Down Expand Up @@ -264,7 +254,7 @@ public override SocketTasks StartClient()
var socketTask = SocketTask.Working;

m_ServerHostId = RelayTransport.AddHost(new HostTopology(GetConfig(), 1), false);
m_ServerConnectionId = RelayTransport.Connect(m_ServerHostId, NetworkAddress, NetworkPort, 0, out byte error);
m_ServerConnectionId = RelayTransport.Connect(m_ServerHostId, ConnectAddress, ConnectPort, 0, out byte error);

var connectError = (NetworkError)error;

Expand Down Expand Up @@ -482,4 +472,4 @@ public IReadOnlyDictionary<string, int> GetTransportProfilerData()
}
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
#pragma warning restore 618
#pragma warning restore 618
6 changes: 3 additions & 3 deletions com.unity.multiplayer.mlapi/Tests/Runtime/RpcQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public IEnumerator RpcQueueUnitTest()
AllowRuntimeSceneChanges = true,
EnableSceneManagement = false
};
unetTransport.NetworkAddress = "127.0.0.1";
unetTransport.NetworkPort = 7777;
unetTransport.ConnectAddress = "127.0.0.1";
unetTransport.ConnectPort = 7777;
unetTransport.ServerListenPort = 7777;
unetTransport.MessageBufferSize = 65535;
unetTransport.MaxConnections = 100;
Expand Down Expand Up @@ -107,4 +107,4 @@ public IEnumerator RpcQueueUnitTest()
#endif
}
}
}
}