コード例 #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();
                }
            }
        }
コード例 #2
0
        public TcpServerConnection(Socket socket)
        {
            this.socket = socket ?? throw new Exception("socket is null");
            stream      = new NetworkStream(socket);

            Log.Main.Inform("Starting connection from " + RemoteIp + ":" + RemotePort);

            receiving_thread = ThreadRoutines.StartTry(
                run,
                (Exception e) =>
            {
                lock (this)
                {
                    if (this.socket == null)    //disposed
                    {
                        return;
                    }
                    if (!IsAlive)
                    {
                        Log.Main.Inform("Connection from " + RemoteIp + ":" + RemotePort + " has been terminated.");
                    }
                    else
                    {
                        Log.Main.Error(e);
                    }
                }
            },
                () =>
            {
                MpegStream.Stop();
                ThreadRoutines.StartTry(Dispose);
            }
                );

            //sending_thread = ThreadRoutines.StartTry(
            //    run,
            //    (Exception e) =>
            //    {
            //        lock (this)
            //        {
            //            if (this.socket == null)//disposed
            //                return;
            //            if (!IsAlive)
            //                Log.Main.Inform("Connection from " + RemoteIp + ":" + RemotePort + " has been terminated.");
            //            else
            //                Log.Main.Error(e);
            //        }
            //    },
            //    () =>
            //    {
            //        ThreadRoutines.StartTry(Dispose);
            //    }
            //    );
        }
コード例 #3
0
 static void stopServingUser()
 {
     if (onNewUser_t != null)
     {
         while (onNewUser_t.IsAlive)
         {
             Log.Main.Write("Terminating onNewUser_t...");
             onNewUser_t.Abort();
             onNewUser_t.Join(200);
         }
         onNewUser_t = null;
     }
     TcpServer.Stop();
     MpegStream.Stop();
 }
コード例 #4
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();
                }
            }
        }