public static Parse ( byte bytes ) : |
||
bytes | byte | |
return |
private void OnClientConnect(ISocket clientSocket) { FleckLog.Debug(String.Format("Client connected from {0}:{1}", clientSocket.RemoteIpAddress, clientSocket.RemotePort.ToString())); ListenForClients(); WebSocketConnection connection = null; connection = new WebSocketConnection( clientSocket, _config, bytes => RequestParser.Parse(bytes, _scheme), r => HandlerFactory.BuildHandler(r, s => connection.OnMessage(s), connection.Close, b => connection.OnBinary(b)), s => SubProtocolNegotiator.Negotiate(SupportedSubProtocols, s)); if (IsSecure) { FleckLog.Debug("Authenticating Secure Connection"); clientSocket .Authenticate(Certificate, connection.StartReceiving, e => FleckLog.Warn("Failed to Authenticate", e)); } else { connection.StartReceiving(); } }
private void OnClientConnect(ISocket clientSocket) { if (clientSocket == null) { return; // socket closed } FleckLog.Debug($"Client connected from {clientSocket.RemoteIpAddress}:{clientSocket.RemotePort.ToString()}"); ListenForClients(); WebSocketConnection connection = null; connection = new WebSocketConnection( clientSocket, _config, bytes => RequestParser.Parse(bytes, _scheme), (c, r) => HandlerFactory.BuildHandler(r, c)); if (IsSecure) { FleckLog.Debug("Authenticating Secure Connection"); clientSocket .Authenticate(Certificate, EnabledSslProtocols, connection.StartReceiving, e => FleckLog.Warn("Failed to Authenticate", e)); } else { connection.StartReceiving(); } }
private void OnClientConnect(ISocket clientSocket) { if (clientSocket == null) { return; // socket closed } FleckLog.Trace($"Client connected from {clientSocket.RemoteIpAddress}:{clientSocket.RemotePort}"); ListenForClients(); WebSocketConnection connection = null; connection = new WebSocketConnection( clientSocket, _config, bytes => RequestParser.Parse(bytes, _scheme), r => HandlerFactory.BuildHandler(r, s => connection.OnMessage(s), connection.Close, b => connection.OnBinary(b), b => connection.OnPing(b), b => connection.OnPong(b)), s => SubProtocolNegotiator.Negotiate(SupportedSubProtocols, s)); if (IsSecure) { FleckLog.Debug("Attempting to secure connection..."); clientSocket.Authenticate(Certificate, EnabledSslProtocols, connection.StartReceiving, e => FleckLog.Error($"Cannot secure the connection: {e.Message}", e)); } else { connection.StartReceiving(); } }
private void OnClientConnect(ISocket clientSocket) { FleckLog.Debug("Client Connected"); ListenForClients(); WebSocketConnection connection = null; connection = new WebSocketConnection( clientSocket, _config, bytes => RequestParser.Parse(bytes, _scheme), r => HandlerFactory.BuildHandler(r, s => connection.OnMessage(s), connection.Close)); if (IsSecure) { FleckLog.Debug("Authenticating Secure Connection"); clientSocket .Authenticate(_x509Certificate, connection.StartReceiving, e => FleckLog.Warn("Failed to Authenticate", e)); } else { connection.StartReceiving(); } }
private void OnClientConnect(ISocket clientSocket) { if (clientSocket == null) { return; // socket closed } ListenForClients(); WebSocketConnection connection = null; connection = new WebSocketConnection( clientSocket, _config, bytes => RequestParser.Parse(bytes, _scheme), r => HandlerFactory.BuildHandler(r, s => connection.OnMessage(s), connection.Close, b => connection.OnBinary(b), b => connection.OnPing(b), b => connection.OnPong(b)), s => SubProtocolNegotiator.Negotiate(SupportedSubProtocols, s)); if (IsSecure) { clientSocket .Authenticate(Certificate, EnabledSslProtocols, connection.StartReceiving, e => FleckLog.Warn("Failed to Authenticate", e)); } else { connection.StartReceiving(); } }
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(); WebSocketConnection connection = null; connection = new WebSocketConnection( clientSocket, _config, bytes => RequestParser.Parse(bytes, _scheme), r => HandlerFactory.BuildHandler(r, s => connection.OnMessage(s), connection.Close, b => connection.OnBinary(b), b => connection.OnPing(b), b => connection.OnPong(b)), s => SubProtocolNegotiator.Negotiate(SupportedSubProtocols, s)); if (IsSecure) { FleckLog.Debug("Authenticating Secure Connection"); Task client = clientSocket .Authenticate(Certificate, EnabledSslProtocols, connection.StartReceiving, e => FleckLog.Warn("Failed to Authenticate", e)); if (client == null) { Console.WriteLine("SSL Fail to Authentication Admin Please check SSL."); FleckLog.Debug("SSL Fail to Authentication Admin Please check SSL."); connection.Close(); } } else { connection.StartReceiving(); } }
private void OnClientConnect(ISocket clientSocket) { if (clientSocket == null) { return; // socket closed } // experimental removed by wmp //FleckLog.Debug(String.Format("Client connected from {0}:{1}", clientSocket.RemoteIpAddress, clientSocket.RemotePort.ToString())); //Console.WriteLine(String.Format("Client connected from {0}:{1}", clientSocket.RemoteIpAddress, clientSocket.RemotePort.ToString())); string rep = string.Empty; bool failed = false; try { rep = clientSocket.RemoteIpAddress; Console.WriteLine("Connecting: " + rep); } catch { Console.WriteLine("Started but IP not available."); failed = true; } //ListenForClients(); if (failed) { try{ clientSocket.Close(); }catch {} try{ clientSocket.Stream.Close(); }catch {} try{ clientSocket.Dispose(); }catch {} return; } WebSocketConnection connection = null; connection = new WebSocketConnection( clientSocket, _config, bytes => RequestParser.Parse(bytes, _scheme), r => HandlerFactory.BuildHandler(r, s => connection.OnMessage(s), connection.Close, b => connection.OnBinary(b), b => connection.OnPing(b), b => connection.OnPong(b)), s => SubProtocolNegotiator.Negotiate(SupportedSubProtocols, s)); if (IsSecure) { FleckLog.Debug("Authenticating Secure Connection"); clientSocket .Authenticate(Certificate, EnabledSslProtocols, () => { Console.WriteLine("Authenticated {0}", rep); Server.Firewall.Update(rep, Server.Firewall.UpdateEntry.AuthSuccess); connection.StartReceiving(); } , e => { FleckLog.Warn("Failed to Authenticate " + rep, e); // here we could add connection.Close() ! wmp Server.Firewall.Update(rep, Server.Firewall.UpdateEntry.AuthFailure); connection.Close(); }); } else { Server.Firewall.Update(rep, Server.Firewall.UpdateEntry.AuthSuccess); connection.StartReceiving(); } }
private void OnClientConnect(ISocket clientSocket) { FleckLog.Debug(String.Format("Client connected from {0}:{1}", clientSocket.RemoteIpAddress, clientSocket.RemotePort.ToString())); ListenForClients(); WebSocketConnection connection = null; connection = new WebSocketConnection( clientSocket, _config, bytes => RequestParser.Parse(bytes, _scheme), r => HandlerFactory.BuildHandler(r, s => connection.OnMessage(s), connection.Close, b => connection.OnBinary(b), b => connection.OnPing(b), b => connection.OnPong(b)), s => SubProtocolNegotiator.Negotiate(SupportedSubProtocols, s)); // Determine whether this is a ws or wss connection try { // Wait up to 5 seconds for the first handshake byte // (Only peek, so it's still in the buffer for the actual handshake handler) byte[] buffer = new byte[1]; clientSocket.Socket.ReceiveTimeout = 5000; int BytesRead = clientSocket.Socket.Receive(buffer, 1, SocketFlags.Peek); clientSocket.Socket.ReceiveTimeout = 0; if (BytesRead == 1) { if ((buffer[0] == 0x16) || (buffer[0] == 0x80)) { // wss connection, ensure we have a certificate if (IsSecure) { FleckLog.Info("Accepting wss:// Connection"); clientSocket .Authenticate(Certificate, connection.StartReceiving, e => { FleckLog.Warn("Failed to Authenticate", e); connection.Close(); }); } else { FleckLog.Warn("Rejecting wss:// connection (no certificate)"); connection.Close(); } } else { // ws connection FleckLog.Info("Accepting ws:// Connection"); connection.StartReceiving(); } } else { connection.Close(); } } catch (Exception ex) { FleckLog.Error("Unable to read handshake byte from client", ex); connection.Close(); } }