// This part was taken from Rick Parrish TelnetDoor almost direct copy pase, with some stuff removed. private static void Connect() { _Server = new TelnetConnection(); if (_Server.Connect(hostURL, _Port)) { bool CanContinue = true; if (CanContinue) { Door.PipeWrite = false; bool UserAborted = false; while (!UserAborted && Door.Carrier && _Server.Connected) { bool Yield = true; // See if the server sent anything to the client if (_Server.CanRead()) { Door.Write(_Server.ReadString()); Yield = false; } // See if the client sent anything to the server if (Door.KeyPressed()) { string ToSend = ""; while (Door.KeyPressed()) { byte B = (byte)Door.ReadByte(); ToSend += (char)B; } _Server.Write(ToSend); Yield = false; } // See if we need to yield if (Yield) Crt.Delay(1); } Door.PipeWrite = true; } } else { Door.WriteLn("Looks like the BBSLink server isn't online, please try back later."); } }
protected override void Execute() { while (!_Stop) { // Accept an incoming control client connection if (_Listener.CanAccept(1000)) // 1 second { try { RaiseMessageEvent("IPCSocketServer about to accept a client connection"); _ClientConnection = _Listener.AcceptTCP(); if (_ClientConnection != null) { string Request = _ClientConnection.ReadLn("\r\n", false, '\0', 1000); if (Request == "OK?") { _ClientConnection.WriteLn("OK!"); RaiseMessageEvent("Control server accepted a client connection from " + _ClientConnection.GetRemoteIP() + ":" + _ClientConnection.GetRemotePort()); _Buffer.Length = 0; while ((!_Stop) && (_ClientConnection.Connected)) { if (_ClientConnection.CanRead(1000)) { ParseClientCommands(_ClientConnection.ReadString()); } } } if (_ClientConnection.Connected) { _ClientConnection.Close(); } } else { RaiseErrorMessageEvent("IPCSocketServer failed to accept a client connection"); } } catch (Exception ex) { RaiseExceptionEvent("Error in IPCSocketServerThread::Execute()", ex); } } } }
protected override void Execute() { while (!_Stop) { Reconnected: try { while ((!_Stop) && (_ClientConnection.Connected)) { // Check for server message if (_ClientConnection.CanRead(1000)) { ParseServerMessages(_ClientConnection.ReadString()); } } } catch (Exception ex) { RaiseExceptionEvent("Error in IPCSocketClientThread::Execute() while communicating", ex); } if (_ClientConnection.Connected) { _ClientConnection.Close(); } while (!_Stop) { try { RaiseMessageEvent("IPSocketClient trying to reconnect..."); if (_ClientConnection.Connect(_RemoteIP, _RemotePort)) { _ClientConnection.WriteLn("OK?"); string Response = _ClientConnection.ReadLn("\r\n", false, '\0', 1000); if (Response == "OK!") { RaiseMessageEvent("IPSocketClient reconnected"); goto Reconnected; } } else { RaiseMessageEvent("IPSocketClient failed to reconnect, trying again in 10 seconds..."); } } catch (Exception ex) { RaiseExceptionEvent("Error in IPCSocketClientThread::Execute() while connecting", ex); } for (int i = 0; i < 10; i++) { if (!_Stop) { break; } Thread.Sleep(1000); } } } }