Skip to content

Commit b755280

Browse files
authored
Merge pull request #185 from MindManager/ReconnectionEvent
Invoke OnReconnectAttempt event from the first attempt
2 parents fb2e4dd + c9dd38e commit b755280

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/SocketIOClient.Sample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static async Task Main(string[] args)
4343
socket.OnPing += Socket_OnPing;
4444
socket.OnPong += Socket_OnPong;
4545
socket.OnDisconnected += Socket_OnDisconnected;
46-
socket.OnReconnecting += Socket_OnReconnecting;
46+
socket.OnReconnectAttempt += Socket_OnReconnecting;
4747

4848
//Console.WriteLine("Press any key to continue");
4949
//Console.ReadLine();

src/SocketIOClient/SocketIO.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ private void Initialize()
189189
public async Task ConnectAsync()
190190
{
191191
Uri wsUri = UrlConverter.HttpToWs(ServerUri, Options);
192+
_reconnectionDelay = Options.ReconnectionDelay;
193+
192194
while (true)
193195
{
194196
try
@@ -197,11 +199,7 @@ public async Task ConnectAsync()
197199
{
198200
break;
199201
}
200-
if (Attempts == 0)
201-
{
202-
_reconnectionDelay = Options.ReconnectionDelay;
203-
}
204-
else if (Attempts > 0)
202+
if (Attempts > 0)
205203
{
206204
OnReconnectAttempt?.Invoke(this, Attempts);
207205
}
@@ -512,7 +510,7 @@ private void ConnectedHandler(ConnectionResult result)
512510
Connected = true;
513511
Disconnected = false;
514512
OnReconnected?.Invoke(this, Attempts);
515-
Attempts = 0;
513+
Attempts = 1;
516514

517515
if (result.Id != null)
518516
{

0 commit comments

Comments
 (0)