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