@@ -104,10 +104,6 @@ public Uri ServerUri
104104 Dictionary < string , Action < SocketIOResponse > > _eventHandlers ;
105105 CancellationTokenSource _connectionTokenSorce ;
106106 double _reconnectionDelay ;
107- CancellationTokenSource _pingTokenSource ;
108- CancellationToken _pingToken ;
109- DateTime _pingTime ;
110-
111107
112108 #region Socket.IO event
113109 public event EventHandler OnConnected ;
@@ -237,25 +233,14 @@ public async Task ConnectAsync()
237233 }
238234 }
239235
240- private async void PingHandler ( )
236+ private void PingHandler ( )
241237 {
242- try
243- {
244- OnPing ? . Invoke ( this , EventArgs . Empty ) ;
245- DateTime pingTime = DateTime . Now ;
246- await Router . SendAsync ( new PongMessage ( ) , CancellationToken . None ) . ConfigureAwait ( false ) ;
247- OnPong ? . Invoke ( this , DateTime . Now - pingTime ) ;
248- }
249- catch ( Exception e )
250- {
251- Debug . WriteLine ( e ) ;
252- InvokeDisconnect ( DisconnectReason . PingTimeout ) ;
253- }
238+ OnPing ? . Invoke ( this , EventArgs . Empty ) ;
254239 }
255240
256- private void PongHandler ( )
241+ private void PongHandler ( PongMessage msg )
257242 {
258- OnPong ? . Invoke ( this , DateTime . Now - _pingTime ) ;
243+ OnPong ? . Invoke ( this , msg . Duration ) ;
259244 }
260245
261246 private void ConnectedHandler ( ConnectedMessage msg )
@@ -268,34 +253,6 @@ private void ConnectedHandler(ConnectedMessage msg)
268253 OnReconnected ? . Invoke ( this , Attempts ) ;
269254 }
270255 Attempts = 0 ;
271- if ( Router . Eio == 3 )
272- {
273- if ( _pingTokenSource != null )
274- {
275- _pingTokenSource . Cancel ( ) ;
276- _pingTokenSource = new CancellationTokenSource ( ) ;
277- _pingToken = _pingTokenSource . Token ;
278- }
279- Task . Factory . StartNew ( PingAsync , TaskCreationOptions . LongRunning ) ;
280- }
281- }
282-
283- private async Task PingAsync ( )
284- {
285- while ( ! _pingToken . IsCancellationRequested )
286- {
287- await Task . Delay ( Router . PingInterval ) ;
288- try
289- {
290- await Router . SendAsync ( new PingMessage ( ) , CancellationToken . None ) . ConfigureAwait ( false ) ;
291- _pingTime = DateTime . Now ;
292- OnPing ? . Invoke ( this , EventArgs . Empty ) ;
293- }
294- catch
295- {
296- InvokeDisconnect ( DisconnectReason . PingTimeout ) ;
297- }
298- }
299256 }
300257
301258 private void DisconnectedHandler ( )
@@ -404,7 +361,7 @@ private void OnMessageReceived(IMessage msg)
404361 PingHandler ( ) ;
405362 break ;
406363 case MessageType . Pong :
407- PongHandler ( ) ;
364+ PongHandler ( msg as PongMessage ) ;
408365 break ;
409366 case MessageType . Connected :
410367 ConnectedHandler ( msg as ConnectedMessage ) ;
@@ -660,7 +617,6 @@ private async void InvokeDisconnect(string reason)
660617 {
661618 Connected = false ;
662619 OnDisconnected ? . Invoke ( this , reason ) ;
663- _pingTokenSource ? . Cancel ( ) ;
664620 try
665621 {
666622 await Router . DisconnectAsync ( ) ;
@@ -697,11 +653,6 @@ public void Dispose()
697653 _eventHandlers . Clear ( ) ;
698654 _connectionTokenSorce . Cancel ( ) ;
699655 _connectionTokenSorce . Dispose ( ) ;
700- if ( _pingTokenSource != null )
701- {
702- _pingTokenSource . Cancel ( ) ;
703- _pingTokenSource . Dispose ( ) ;
704- }
705656 }
706657 }
707658}
0 commit comments