예제 #1
0
 public Server()
 {
     ConsoleTimeLogger.WriteLine("Creating server...", Console.Out);
     _serverThread              = new Thread(Loop);
     _serverThread.Name         = "Server Thread";
     _serverThread.IsBackground = true;
     _serverThread.Start();
 }
예제 #2
0
        void DoWork()
        {
            int    i = 0;
            string recievedData;

            byte[] buffer;
            while (!_shouldStop)
            {
                buffer = new byte[Constants.bufferLength];
                i      = _clientSocket.Receive(buffer);

                if (i > 0)
                {
                    recievedData = StringBytesConverter.GetString(buffer);

                    ConsoleTimeLogger.WriteLine("< " + recievedData, Console.Out);
                    switch (recievedData)
                    {
                    case Commands.exitClient:
                        Stop("client exited.");
                        KillChildProcesses(_cmdProcess);
                        break;

                    case Commands.stopClient:
                        Stop("client stopped.");
                        break;

                    case Commands.restartServer:
                        Stop("client wished to stop me.");
                        break;

                    case Commands.clientConnected:
                        _clientSocket.Send(StringBytesConverter.GetBytes(Constants.uiServerGreeting));
                        break;

                    case Commands.emptyLine:
                        _clientSocket.Send(StringBytesConverter.GetBytes(recievedData));
                        break;

                    default:
                        if (Channels.IsAvailableChannel(recievedData))
                        {
                            StartDumpingAndForwardingStream(recievedData);
                            _clientSocket.Send(StringBytesConverter.GetBytes(Commands.translationStarted));
                        }
                        else
                        {
                            _clientSocket.Send(StringBytesConverter.GetBytes(recievedData + Constants.uiServerDontKnow));
                        }
                        break;
                    }
                }
            }
        }
예제 #3
0
 public void Stop(string reason)
 {
     if (!_shouldStop)
     {
         _shouldStop = true;
         ConsoleTimeLogger.WriteLine("Stopped. Reason: " + reason + Environment.NewLine, Console.Out);
         CloseConnections();
         KillChildProcesses(_cmdProcess);
     }
     else
     {
         ConsoleTimeLogger.WriteLine("Already stopped. New reason: " + reason + Environment.NewLine, Console.Out);
     }
 }