Skip to content

Commit

Permalink
fix: making WebSocketClientStandAlone use timeouts from inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Oct 12, 2020
1 parent 494086c commit 504e6a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions source/Client/SimpleWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public enum ClientState
/// </summary>
public abstract class SimpleWebClient
{
public static SimpleWebClient Create(int maxMessageSize, int maxMessagesPerTick)
public static SimpleWebClient Create(int maxMessageSize, int maxMessagesPerTick, int sendTimeout, int receiveTimeout)
{
#if UNITY_WEBGL && !UNITY_EDITOR
return new WebSocketClientWebGl(maxMessageSize, maxMessagesPerTick);
#else
return new WebSocketClientStandAlone(maxMessageSize, maxMessagesPerTick);
return new WebSocketClientStandAlone(maxMessageSize, maxMessagesPerTick, sendTimeout, receiveTimeout);
#endif
}

Expand Down
10 changes: 7 additions & 3 deletions source/Client/StandAlone/WebSocketClientStandAlone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ internal class WebSocketClientStandAlone : SimpleWebClient
readonly RNGCryptoServiceProvider random;

private Connection conn;
readonly int sendTimeout;
readonly int receiveTimeout;

internal WebSocketClientStandAlone(int maxMessageSize, int maxMessagesPerTick) : base(maxMessageSize, maxMessagesPerTick)
internal WebSocketClientStandAlone(int maxMessageSize, int maxMessagesPerTick, int sendTimeout, int receiveTimeout) : base(maxMessageSize, maxMessagesPerTick)
{
#if UNITY_WEBGL && !UNITY_EDITOR
throw new NotSupportedException();
#else
sslHelper = new ClientSslHelper();
handshake = new ClientHandshake();
random = new RNGCryptoServiceProvider();
this.sendTimeout = sendTimeout;
this.receiveTimeout = receiveTimeout;
#endif
}
~WebSocketClientStandAlone()
Expand All @@ -46,8 +50,8 @@ void ConnectAndReceiveLoop(string address)
{
TcpClient client = new TcpClient();
client.NoDelay = true;
client.ReceiveTimeout = 20000;
client.SendTimeout = 5000;
client.ReceiveTimeout = receiveTimeout;
client.SendTimeout = sendTimeout;
Uri uri = new Uri(address);
try
{
Expand Down
2 changes: 1 addition & 1 deletion source/SimpleWebTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public override void ClientConnect(string hostname)
Port = port
};

client = SimpleWebClient.Create(maxMessageSize, clientMaxMessagesPerTick);
client = SimpleWebClient.Create(maxMessageSize, clientMaxMessagesPerTick, sendTimeout, receiveTimeout);
if (client == null) { return; }

client.onConnect += OnClientConnected.Invoke;
Expand Down

0 comments on commit 504e6a0

Please sign in to comment.