Пример #1
0
        void onReceive(AbstractTcpSocket socket, Socket client, byte[] bytes)
        {
            var message = Encoding.UTF8.GetString(bytes);

            fabl.Info(message);

            var args = getArgsFromMessage(message);

            try {
                if (args[0] == trigger)
                {
                    throw new Exception("Server is already running!");
                }
                var command = Program.GetCommand(args[0]);
                fabl.AddAppender(onLog);
                command.Run(args);
                fabl.RemoveAppender(onLog);
                var logBufferString = getLogBufferString();
                var sendBytes       = logBufferString.Length == 0
                    ? new byte[] { 0 }
                    : Encoding.UTF8.GetBytes(logBufferString);
                socket.Send(sendBytes);
            } catch (Exception ex) {
                Program.PrintException(ex, args);
                socket.Send(Encoding.UTF8.GetBytes(getLogBufferString() + ex.Message));
            }

            _logBuffer.Clear();
        }
Пример #2
0
 static void start()
 {
     _socket.OnReceive      += onReceive;
     Console.CancelKeyPress += onCancel;
     while (true)
     {
         _socket.Send(Encoding.UTF8.GetBytes(Console.ReadLine() + "\n"));
     }
 }