Skip to content

Commit

Permalink
Fixed issue when socket was closed by server while connecting
Browse files Browse the repository at this point in the history
If the socket connection is closed by the server while connecting
(meaning the connection establishment effectively failed but without an
error), the user wasnot be notified because the status is "Connecting"
and OnClosed will not fire the event in that case which gives the user
no chance to react to this event.
In this case the status must be changed to "Closing" (similar to
client_Error) to trigger the event.
  • Loading branch information
larskn committed Jun 6, 2014
1 parent eba1da3 commit 3dddbb4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions WebSocket4Net/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ void client_Error(object sender, ErrorEventArgs e)

void client_Closed(object sender, EventArgs e)
{
//If the socket connection is closed by the server while connecting (meaning
//the connection establishment effectively failed but without an error), the
//user will not be notified if the status is "Connecting" because OnClosed
//will not fire the event which gives the user no chance to react to this event.
//Therefore the status must be changed to "Closing" (similar to client_Error)
//to trigger the event.
if (m_StateCode == WebSocketStateConst.Connecting)
{
m_StateCode = WebSocketStateConst.Closing;
}

OnClosed();
}

Expand Down

0 comments on commit 3dddbb4

Please sign in to comment.