Ejemplo n.º 1
0
        public void Listen(int port, HttpDispatcher http)
        {
            // websocket handling
            http.WebSocketOpened
            .Subscribe(ws =>
            {
                AddSession(ws);
                ws.Closed += () =>
                {
                    RemoveSession(ws);
                };
            });

            // listen http
            m_disposable = ListenObservable.Listen(port).Subscribe(x =>
            {
                http.Process(x, new byte[1024]);
            },
                                                                   ex =>
            {
                if (ex is ObjectDisposedException)
                {
                }
                else
                {
                    Logging.Exception(ex);
                }
            })
            ;
        }
Ejemplo n.º 2
0
        private void OnEnable()
        {
            Logging.Info("listen " + m_port);
            var m_http = new HttpDispatcher(SetupHttpMount());

            m_console = new WSConsole();
            m_console.Listen(m_port, m_http);

            var utf8 = new System.Text.UTF8Encoding(false);

            m_disposable = Logging.Observable.Subscribe(x =>
            {
                try
                {
                    // LogEntry to Json
                    var json = UnityEngine.JsonUtility.ToJson(x);
                    m_console.SendFrame(WebSocketFrameOpCode.Text, new ArraySegment <byte>(utf8.GetBytes(json)));
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            });
        }