SimpleWebTransport: ClientConnect "IP:Port" support

This commit is contained in:
vis2k 2021-05-27 18:54:41 +08:00
parent 10d6ffbb28
commit 0198551cc9

View File

@ -122,7 +122,7 @@ public override bool ClientConnected()
return client != null && client.ConnectionState != ClientState.NotConnected; return client != null && client.ConnectionState != ClientState.NotConnected;
} }
public override void ClientConnect(string hostname) public override void ClientConnect(string address)
{ {
// connecting or connected // connecting or connected
if (ClientConnected()) if (ClientConnected())
@ -131,13 +131,28 @@ public override void ClientConnect(string hostname)
return; return;
} }
UriBuilder builder = new UriBuilder UriBuilder builder;
// "Host:Port"
if (Mirror.Utils.ParseHostAndPort(address, out string parsedHost, out ushort parsedPort))
{
builder = new UriBuilder
{ {
Scheme = GetClientScheme(), Scheme = GetClientScheme(),
Host = hostname, Host = parsedHost,
Port = parsedPort
};
}
// "Host" and default port
else
{
builder = new UriBuilder
{
Scheme = GetClientScheme(),
Host = address,
Port = port Port = port
}; };
}
client = SimpleWebClient.Create(maxMessageSize, clientMaxMessagesPerTick, TcpConfig); client = SimpleWebClient.Create(maxMessageSize, clientMaxMessagesPerTick, TcpConfig);
if (client == null) { return; } if (client == null) { return; }