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; } } } }
void DoWork() { string sendData; string recievedData; byte[] buffer; bool beginning = true; while (!_shouldStop) { buffer = new byte[Constants.bufferLength]; if (beginning) { sendData = Commands.clientConnected; beginning = false; } else { sendData = EnterCommand(); } _socket.Send(StringBytesConverter.GetBytes(sendData)); if (sendData == Commands.exitClient) { Kill(); break; } _socket.Receive(buffer); recievedData = StringBytesConverter.GetString(buffer); Console.WriteLine("<" + recievedData); switch (recievedData) { case Commands.translationStarted: Launch(); break; case Commands.serverStopped: Stop(Commands.serverStopped); break; case Constants.uiServerGreeting: OnServerGreeting(); break; default: break; } } }
void CloseConnections() { if (_clientSocket != null) { try { _clientSocket.Send(StringBytesConverter.GetBytes(Commands.serverStopped)); _clientSocket.Send(StringBytesConverter.GetBytes(Constants.uiServerStopping)); } catch { } _clientSocket.Close(); } if (_tcpListener != null) { _tcpListener.Stop(); } }
void CloseConnetions() { IsConnected = false; if (_socket != null) { try { _socket.Send(StringBytesConverter.GetBytes(Commands.stopClient)); } catch { } _socket.Close(); } if (_tcpClient != null) { _tcpClient.Close(); } }