Skip to content

fix: Endpoint creation fails with empty listen address #1636

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 2 commits into from
Jan 29, 2022
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
2 changes: 2 additions & 0 deletions com.unity.netcode.adapter.utp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ All notable changes to this package will be documented in this file. The format

### Fixed

- Fixed issue where the server `NetworkEndPoint` would fail to be created when 'Server Listen Address' is empty. (#1636)

## [1.0.0-pre.5] - 2022-01-26

### Added
Expand Down
11 changes: 6 additions & 5 deletions com.unity.netcode.adapter.utp/Runtime/UnityTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private enum State
public const int InitialMaxSendQueueSize = 16 * InitialMaxPayloadSize;

private static ConnectionAddressData s_DefaultConnectionAddressData = new ConnectionAddressData()
{ Address = "127.0.0.1", Port = 7777, ServerListenAddress = null };
{ Address = "127.0.0.1", Port = 7777, ServerListenAddress = string.Empty };

#pragma warning disable IDE1006 // Naming Styles
public static INetworkStreamDriverConstructor s_DriverConstructor;
Expand Down Expand Up @@ -153,15 +153,16 @@ private static NetworkEndPoint ParseNetworkEndpoint(string ip, ushort port)

public NetworkEndPoint ServerEndPoint => ParseNetworkEndpoint(Address, Port);

public NetworkEndPoint ListenEndPoint => ParseNetworkEndpoint(ServerListenAddress ?? Address, Port);
public NetworkEndPoint ListenEndPoint => ParseNetworkEndpoint(
(ServerListenAddress == string.Empty) ? Address : ServerListenAddress, Port);

[Obsolete("Use ServerEndPoint or ListenEndPoint properties instead.")]
public static implicit operator NetworkEndPoint(ConnectionAddressData d) =>
ParseNetworkEndpoint(d.Address, d.Port);

[Obsolete("Construct manually from NetworkEndPoint.Address and NetworkEndPoint.Port instead.")]
public static implicit operator ConnectionAddressData(NetworkEndPoint d) =>
new ConnectionAddressData() { Address = d.Address.Split(':')[0], Port = d.Port, ServerListenAddress = null };
new ConnectionAddressData() { Address = d.Address.Split(':')[0], Port = d.Port, ServerListenAddress = string.Empty };
}

public ConnectionAddressData ConnectionData = s_DefaultConnectionAddressData;
Expand Down Expand Up @@ -442,7 +443,7 @@ public void SetConnectionData(string ipv4Address, ushort port, string listenAddr
{
Address = ipv4Address,
Port = port,
ServerListenAddress = listenAddress
ServerListenAddress = listenAddress ?? string.Empty
};

SetProtocol(ProtocolType.UnityTransport);
Expand All @@ -455,7 +456,7 @@ public void SetConnectionData(NetworkEndPoint endPoint, NetworkEndPoint listenEn
{
string serverAddress = endPoint.Address.Split(':')[0];

string listenAddress = null;
string listenAddress = string.Empty;
if (listenEndPoint != default)
{
listenAddress = listenEndPoint.Address.Split(':')[0];
Expand Down