Skip to content
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

クライアント側での再接続時間オーバーしたとき、もう1回だけ再接続を試す #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

makiuchi-d
Copy link
Member

クライアント側での通信例外発生時に再接続時間切れしたとき、
通信遅延などでサーバ側ではまだタイムアウトしていないケースがあるので、
1回だけ再接続をトライするようにしてみました。

@makiuchi-d makiuchi-d requested a review from inada-s June 24, 2024 10:18
@makiuchi-d
Copy link
Member Author

無理やりですが、動作確認はコードをいじれば。

diff --git a/wsnet2-dotnet/WSNet2.Client/Client.cs b/wsnet2-dotnet/WSNet2.Client/Client.cs
index a6e8831..95cccb4 100644
--- a/wsnet2-dotnet/WSNet2.Client/Client.cs
+++ b/wsnet2-dotnet/WSNet2.Client/Client.cs
@@ -437,7 +437,7 @@ namespace WSNet2.DotnetClient
                     {"aaa", "private"},
                     {"ccc", false},
                 };
-                var roomOpt = new RoomOption(10, SearchGroup, pubProps, privProps).WithClientDeadline(30).WithNumber(true);
+                var roomOpt = new RoomOption(10, SearchGroup, pubProps, privProps).WithClientDeadline(15).WithNumber(true);
 
                 client.Create(roomOpt, cliProps, onJoined, onFailed, null);
             }
diff --git a/wsnet2-unity/Assets/WSNet2/Scripts/Core/Connection.cs b/wsnet2-unity/Assets/WSNet2/Scripts/Core/Connection.cs
index aff918b..93cac33 100644
--- a/wsnet2-unity/Assets/WSNet2/Scripts/Core/Connection.cs
+++ b/wsnet2-unity/Assets/WSNet2/Scripts/Core/Connection.cs
@@ -247,7 +247,7 @@ namespace WSNet2
                     ct.ThrowIfCancellationRequested();
                     var ev = await ReceiveEvent(ws, ct);
 
-                    this.reconnectLimit = DateTime.Now.AddSeconds(room.ClientDeadline);
+                    this.reconnectLimit = DateTime.Now.AddSeconds(room.ClientDeadline/2);
                     this.reconnectLimitException = null;
 
                     if (ev.IsRegular)
@@ -379,8 +379,13 @@ namespace WSNet2
         {
             var msg = new MsgPing(hmac);
 
+            var n = 0;
+
             while (true)
             {
+                n++;
+                bool clog = n % 5 == 0;
+
                 if (ct.IsCancellationRequested)
                 {
                     return; // ctのキャンセルで終了
@@ -389,7 +394,12 @@ namespace WSNet2
                 var interval = Task.Delay(pingInterval, pingerDelayCanceller.Token);
                 var time = (uint)msg.SetTimestamp();
                 lastPingTime = time;
+                if (clog) await Task.Delay(10000);
                 await Send(ws, msg.Value, ct);
+                if (clog) {
+                    await Task.Delay(10000);
+                    throw new Exception("Clogged");
+                }
                 try
                 {
                     await interval;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant