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

add an event handler for when the websocket client detects a missing pong... #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions WebSocket4Net.MonoDroid/WebSocket4Net.MonoDroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
<Compile Include="..\WebSocket4Net\OpCode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="..\WebSocket4Net\PongTimeoutEventArgs.cs">
<Link>PongTimeoutEventArgs.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\WebSocket4Net\Protocol\CloseStatusCodeHybi10.cs">
<SubType>Code</SubType>
Expand Down
3 changes: 3 additions & 0 deletions WebSocket4Net.MonoTouch/WebSocket4Net.MonoTouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
<Compile Include="..\WebSocket4Net\OpCode.cs">
<Link>OpCode.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\PongTimeoutEventArgs.cs">
<Link>PongTimeoutEventArgs.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\Protocol\CloseStatusCodeHybi10.cs">
<Link>Protocol\CloseStatusCodeHybi10.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions WebSocket4Net.Silverlight/WebSocket4Net.SL40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
<Compile Include="..\WebSocket4Net\OpCode.cs">
<Link>OpCode.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\PongTimeoutEventArgs.cs">
<Link>PongTimeoutEventArgs.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\Protocol\CloseStatusCodeHybi10.cs">
<Link>Protocol\CloseStatusCodeHybi10.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions WebSocket4Net.Silverlight/WebSocket4Net.SL50.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<Compile Include="..\WebSocket4Net\OpCode.cs">
<Link>OpCode.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\PongTimeoutEventArgs.cs">
<Link>PongTimeoutEventArgs.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\Protocol\CloseStatusCodeHybi10.cs">
<Link>Protocol\CloseStatusCodeHybi10.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions WebSocket4Net.WP71/WebSocket4Net.WP71.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<Compile Include="..\WebSocket4Net\OpCode.cs">
<Link>OpCode.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\PongTimeoutEventArgs.cs">
<Link>PongTimeoutEventArgs.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\Protocol\CloseStatusCodeHybi10.cs">
<Link>Protocol\CloseStatusCodeHybi10.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions WebSocket4Net.WP80/WebSocket4Net.WP80.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@
<Compile Include="..\WebSocket4Net\OpCode.cs">
<Link>OpCode.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\PongTimeoutEventArgs.cs">
<Link>PongTimeoutEventArgs.cs</Link>
</Compile>
<Compile Include="..\WebSocket4Net\Protocol\CloseStatusCodeHybi10.cs">
<Link>Protocol\CloseStatusCodeHybi10.cs</Link>
</Compile>
Expand Down
16 changes: 16 additions & 0 deletions WebSocket4Net/PongTimeoutEventArgs.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
19 changes: 19 additions & 0 deletions WebSocket4Net/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -533,6 +536,22 @@ public void Close(int statusCode, string reason)
ProtocolProcessor.SendCloseHandshake(this, statusCode, reason);
}

private EventHandler<PongTimeoutEventArgs> m_PongTimeout;

public event EventHandler<PongTimeoutEventArgs> 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)
Expand Down