public static void StopListenNewBlocks() { if (webSocket != null) { webSocket.Close(); } webSocket = null; }
public override void Stop() { // Close the socket so that any waits on ReadLn(), ReadChar(), etc, will not block if (_Server != null) { _Server.Close(); } base.Stop(); }
protected override void HandleNewConnection(TcpConnection newConnection) { if (newConnection == null) { throw new ArgumentNullException("newConnection"); } WebSocketConnection TypedConnection = new WebSocketConnection(); if (TypedConnection.Open(newConnection.GetSocket())) { // TODOX Start a proxy thread instead of a clientthread ClientThread NewClientThread = new ClientThread(TypedConnection, _ConnectionType); NewClientThread.Start(); } else { RMLog.Info("No carrier detected (probably a portscanner)"); TypedConnection.Close(); } }
public async Task <IActionResult> Get() { var context = ControllerContext.HttpContext; if (context.WebSockets.IsWebSocketRequest) { var webSocket = await context.WebSockets.AcceptWebSocketAsync(); Console.WriteLine($"Accepted connection '{context.Connection.Id}'"); var connection = new WebSocketConnection(webSocket); await connection.ReceiveUntilClose(); await connection.Close(); return(new EmptyResult()); } else { return(new StatusCodeResult((int)HttpStatusCode.BadRequest)); } }
public void Disconnect(bool waitForComplete) { CheckIfCalledOnValidThread(); Logger.Debug(TAG, $"Disconnect WebSocket. State: {State}"); if (State == WebSocketConnectionState.Registered) { // Send "bye" to WebSocket server. SendByeMessage(); State = WebSocketConnectionState.Connected; } if (State == WebSocketConnectionState.Connected || State == WebSocketConnectionState.Error) { if (waitForComplete) { _mre = new ManualResetEvent(false); } WebSocketConnection.Close(); State = WebSocketConnectionState.Closed; if (waitForComplete) { try { _mre.WaitOne(CloseTimeout); } catch (Exception ex) { Logger.Error(TAG, $"Wait error:{ex}"); } } } UnWireEvents(); Logger.Debug(TAG, "Disconnecting WebSocket done."); }
protected override void Execute() { using (TcpConnection Connection = new TcpConnection()) { if (Connection.Listen(_LocalAddress, _LocalPort)) { RaiseBoundEvent(); while (!_Stop) { // Accept an incoming connection if (Connection.CanAccept(1000)) // 1 second { try { TcpConnection NewConnection = Connection.AcceptTCP(); if (NewConnection != null) { TcpConnection TypedConnection = null; switch (_ConnectionType) { case ConnectionType.RLogin: TypedConnection = new RLoginConnection(); break; case ConnectionType.Telnet: TypedConnection = new TelnetConnection(); break; case ConnectionType.WebSocket: TypedConnection = new WebSocketConnection(); break; } if (TypedConnection != null) { TypedConnection.Open(NewConnection.GetSocket()); if (IsIgnoredIP(TypedConnection.GetRemoteIP())) { // Do nothing for ignored IPs TypedConnection.Close(); } else { RaiseMessageEvent("Incoming " + _ConnectionType.ToString() + " connection from " + TypedConnection.GetRemoteIP() + ":" + TypedConnection.GetRemotePort()); TerminalType TT = GetTerminalType(TypedConnection); if (IsBannedIP(TypedConnection.GetRemoteIP())) { DisplayAnsi("IP_BANNED", TypedConnection, TT); RaiseWarningMessageEvent("IP " + TypedConnection.GetRemoteIP() + " matches banned IP filter"); TypedConnection.Close(); } else if (_Paused) { DisplayAnsi("SERVER_PAUSED", TypedConnection, TT); TypedConnection.Close(); } else { if (!TypedConnection.Connected) { RaiseMessageEvent("No carrier detected (maybe it was a 'ping'?)"); TypedConnection.Close(); } else { ClientThread NewClientThread = new ClientThread(); int NewNode = RaiseConnectEvent(ref NewClientThread); if (NewNode == 0) { NewClientThread.Dispose(); DisplayAnsi("SERVER_BUSY", TypedConnection, TT); TypedConnection.Close(); } else { NewClientThread.Start(NewNode, TypedConnection, _ConnectionType, TT); } } } } } } } catch (Exception ex) { RaiseExceptionEvent("Error in ServerThread::Execute()", ex); } } } } else { RaiseErrorMessageEvent("Server Thread unable to listen on " + _LocalAddress + ":" + _LocalPort); RaiseBindFailedEvent(); } } }
public void Close() { _websocketcon.Close(); }