public void Start(Action <IWebSocketConnection> config) { var ipLocal = new IPEndPoint(_locationIP, Port); ListenerSocket.Bind(ipLocal); ListenerSocket.Listen(100); Port = ((IPEndPoint)ListenerSocket.LocalEndPoint).Port; FleckLog.Info(string.Format("Server started at {0} (actual port {1})", Location, Port)); if (_scheme == "wss") { if (Certificate == null) { FleckLog.Error("Scheme cannot be 'wss' without a Certificate"); return; } if (EnabledSslProtocols == SslProtocols.None) { EnabledSslProtocols = SslProtocols.Tls; FleckLog.Debug("Using default TLS 1.0 security protocol."); } } ListenForClients(); _config = config; }
private Task SendBytes(byte[] bytes, Action callback = null) { return(Socket.Send(bytes, () => { FleckLog.Debug("Sent " + bytes.Length + " bytes"); if (callback != null) { callback(); } }, e => { if (e is IOException) { FleckLog.Debug("Failed to send. Disconnecting.", e); } else { FleckLog.Info("Failed to send. Disconnecting.", e); } CloseSocket(); })); }