diff --git a/WebSocket4Net.MonoDroid/WebSocket4Net.MonoDroid.csproj b/WebSocket4Net.MonoDroid/WebSocket4Net.MonoDroid.csproj index d0773a10..a05a9158 100644 --- a/WebSocket4Net.MonoDroid/WebSocket4Net.MonoDroid.csproj +++ b/WebSocket4Net.MonoDroid/WebSocket4Net.MonoDroid.csproj @@ -119,6 +119,9 @@ Code + + PongTimeoutEventArgs.cs + Code diff --git a/WebSocket4Net.MonoTouch/WebSocket4Net.MonoTouch.csproj b/WebSocket4Net.MonoTouch/WebSocket4Net.MonoTouch.csproj index 50d5153d..21382a4d 100644 --- a/WebSocket4Net.MonoTouch/WebSocket4Net.MonoTouch.csproj +++ b/WebSocket4Net.MonoTouch/WebSocket4Net.MonoTouch.csproj @@ -110,6 +110,9 @@ OpCode.cs + + PongTimeoutEventArgs.cs + Protocol\CloseStatusCodeHybi10.cs diff --git a/WebSocket4Net.Silverlight/WebSocket4Net.SL40.csproj b/WebSocket4Net.Silverlight/WebSocket4Net.SL40.csproj index fc574d38..bbdab72b 100644 --- a/WebSocket4Net.Silverlight/WebSocket4Net.SL40.csproj +++ b/WebSocket4Net.Silverlight/WebSocket4Net.SL40.csproj @@ -122,6 +122,9 @@ OpCode.cs + + PongTimeoutEventArgs.cs + Protocol\CloseStatusCodeHybi10.cs diff --git a/WebSocket4Net.Silverlight/WebSocket4Net.SL50.csproj b/WebSocket4Net.Silverlight/WebSocket4Net.SL50.csproj index 9d383ac9..0e2dfea6 100644 --- a/WebSocket4Net.Silverlight/WebSocket4Net.SL50.csproj +++ b/WebSocket4Net.Silverlight/WebSocket4Net.SL50.csproj @@ -123,6 +123,9 @@ OpCode.cs + + PongTimeoutEventArgs.cs + Protocol\CloseStatusCodeHybi10.cs diff --git a/WebSocket4Net.WP71/WebSocket4Net.WP71.csproj b/WebSocket4Net.WP71/WebSocket4Net.WP71.csproj index 70ee03a4..895fd9c8 100644 --- a/WebSocket4Net.WP71/WebSocket4Net.WP71.csproj +++ b/WebSocket4Net.WP71/WebSocket4Net.WP71.csproj @@ -117,6 +117,9 @@ OpCode.cs + + PongTimeoutEventArgs.cs + Protocol\CloseStatusCodeHybi10.cs diff --git a/WebSocket4Net.WP80/WebSocket4Net.WP80.csproj b/WebSocket4Net.WP80/WebSocket4Net.WP80.csproj index 118a59e9..a8b3426d 100644 --- a/WebSocket4Net.WP80/WebSocket4Net.WP80.csproj +++ b/WebSocket4Net.WP80/WebSocket4Net.WP80.csproj @@ -160,6 +160,9 @@ OpCode.cs + + PongTimeoutEventArgs.cs + Protocol\CloseStatusCodeHybi10.cs diff --git a/WebSocket4Net/PongTimeoutEventArgs.cs b/WebSocket4Net/PongTimeoutEventArgs.cs new file mode 100644 index 00000000..52afdafd --- /dev/null +++ b/WebSocket4Net/PongTimeoutEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WebSocket4Net +{ + public class PongTimeoutEventArgs : EventArgs + { + public PongTimeoutEventArgs(string message) + { + Message = message; + } + + public string Message { get; private set; } + } +} diff --git a/WebSocket4Net/WebSocket.cs b/WebSocket4Net/WebSocket.cs index 10ff140d..765fc777 100644 --- a/WebSocket4Net/WebSocket.cs +++ b/WebSocket4Net/WebSocket.cs @@ -381,6 +381,9 @@ private void OnPingTimerCallback(object state) if (!string.IsNullOrEmpty(m_LastPingRequest) && !m_LastPingRequest.Equals(LastPongResponse)) { //have not got last response + m_LastPingRequest = null; + LastPongResponse = null; + FirePongTimeout(String.Format("Pong not received within {0}s of ping", AutoSendPingInterval)); return; } @@ -533,6 +536,22 @@ public void Close(int statusCode, string reason) ProtocolProcessor.SendCloseHandshake(this, statusCode, reason); } + private EventHandler m_PongTimeout; + + public event EventHandler PongTimeout + { + add { m_PongTimeout += value; } + remove { m_PongTimeout -= value; } + } + + internal void FirePongTimeout(string message) + { + if (m_PongTimeout == null) + return; + + m_PongTimeout(this, new PongTimeoutEventArgs(message)); + } + private void CheckCloseHandshake(object state) { if (m_StateCode == WebSocketStateConst.Closed)