Esempio n. 1
0
        // 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.");
            }
        }
Esempio n. 2
0
        public static IPCSocketClientThread GetNewClient(string remoteAddress, int remotePort)
        {
            TcpConnection ClientConnection = new TcpConnection();

            if (ClientConnection.Connect(remoteAddress, remotePort))
            {
                ClientConnection.WriteLn("OK?");
                string Response = ClientConnection.ReadLn("\r\n", false, '\0', 1000);
                if (Response == "OK!")
                {
                    IPCSocketClientThread Result = new IPCSocketClientThread(ClientConnection);
                    Result.Start();
                    return(Result);
                }
            }

            return(null);
        }
Esempio n. 3
0
        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);
                    }
                }
            }
        }