Exemplo n.º 1
0
        void run()
        {
            while (receiving_thread != null)
            {
                TcpMessage m = receive_message();

                Log.Main.Inform("Tcp message received: " + m.Name + "\r\n" + m.BodyAsText);
                UiApi.Message(MessageType.INFORM, "Tcp message received: " + m.Name + "\r\n" + m.BodyAsText);

                string reply = TcpMessage.Success;
                try
                {
                    switch (m.Name)
                    {
                    case TcpMessage.FfmpegStart:
                        MpegStream.Start(Service.UserSessionId, m.BodyAsText);
                        break;

                    case TcpMessage.FfmpegStop:
                        MpegStream.Stop();
                        break;

                    case TcpMessage.SslStart:
                        if (stream is SslStream)
                        {
                            throw new Exception("SSL is already started.");
                        }
                        break;

                    case TcpMessage.Poll:
                        lock (errors)
                        {
                            if (errors.Count > 0)
                            {
                                reply = string.Join("\r\n", errors);
                                errors.Clear();
                            }
                        }
                        break;

                    default:
                        throw new Exception("Unknown message: " + m.Name);
                    }
                }
                catch (Exception e)
                {
                    reply = e.Message;
                    Log.Main.Error("Tcp message processing: ", e);
                }
                Log.Main.Inform("Tcp message sending: " + m.Name + "\r\n" + reply);

                TcpMessage m2 = new TcpMessage(m.Name, reply);
                send_message(m2);

                if (m.Name == TcpMessage.SslStart && reply == TcpMessage.Success)
                {
                    startSsl();
                }
            }
        }
Exemplo n.º 2
0
 void send_message(TcpMessage message)
 {
     byte[] sizeAsBytes = BitConverter.GetBytes(message.Size);
     stream.Write(sizeAsBytes, 0, sizeAsBytes.Length);
     //throw new Exception("Could not send to stream the required count of bytes: " + sizeAsBytes.Length);
     stream.Write(message.NameBodyAsBytes, 0, message.NameBodyAsBytes.Length);
     //throw new Exception("Could not send to stream the required count of bytes: " + NameBodyAsBytes.Length);
 }
Exemplo n.º 3
0
        void run()
        {
            while (thread != null)
            {
                TcpMessage m = TcpMessage.Receive(stream);

                Log.Main.Inform("Tcp message received: " + m.Name + "\r\n" + m.BodyAsText);
                CisteraScreenCaptureService.ExposedEvents.UiMessage.Info("Tcp message received: " + m.Name + "\r\n" + m.BodyAsText);

                string reply = TcpMessage.Success;
                try
                {
                    switch (m.Name)
                    {
                    case TcpMessage.FfmpegStart:
                        MpegStream.Start(Service.UserSessionId, m.BodyAsText);
                        break;

                    case TcpMessage.FfmpegStop:
                        MpegStream.Stop();
                        break;

                    case TcpMessage.SslStart:
                        if (stream is SslStream)
                        {
                            throw new Exception("SSL is already started.");
                        }
                        break;

                    default:
                        throw new Exception("Unknown message: " + m.Name);
                    }
                }
                catch (Exception e)
                {
                    reply = e.Message;
                    Log.Main.Error("Tcp message processing: ", e);
                }
                Log.Main.Inform("Tcp message sending: " + m.Name + "\r\n" + reply);
                m.Reply(stream, reply);
                if (m.Name == TcpMessage.SslStart && reply == TcpMessage.Success)
                {
                    startSsl();
                }
            }
        }
Exemplo n.º 4
0
        public void Reply(Stream stream, string body)
        {
            TcpMessage m = new TcpMessage(Name, body);

            m.send(stream);
        }