Skip to content
Open
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
16 changes: 13 additions & 3 deletions src/Fleck/WebSocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,18 @@ public void Start(Action<IWebSocketConnection> config)
_config = config;
}

private void ListenForClients()
private void ListenForClients(int retryCount = 0)
{
ListenerSocket.Accept(OnClientConnect, e => FleckLog.Error("Listener socket is closed", e));
ListenerSocket.Accept(OnClientConnect, (e => ListenForClientsExceptionHandler(e, retryCount)));
}

private void OnClientConnect(ISocket clientSocket)
{
if (clientSocket == null) return; // socket closed

FleckLog.Debug(String.Format("Client connected from {0}:{1}", clientSocket.RemoteIpAddress, clientSocket.RemotePort.ToString()));
ListenForClients();

ListenForClients();

WebSocketConnection connection = null;

Expand Down Expand Up @@ -125,5 +126,14 @@ private void OnClientConnect(ISocket clientSocket)
connection.StartReceiving();
}
}

private void ListenForClientsExceptionHandler(Exception e, int retryCount)
{
FleckLog.Error("Listener socket is closed", e);
if (retryCount > 1000)
return;
FleckLog.Info("Trying to open listener socket for the " + retryCount + ". time");
ListenForClients(retryCount + 1);
}
}
}