// This gets called by BaseHttpServer and gives us an opportunity to set things on the WebSocket handler before we turn it on
 public void WebSocketHandlerCallback(string path, WebSocketHttpServerHandler handler)
 {
     SubscribeToEvents(handler);
     handler.SetChunksize(8192);
     handler.NoDelay_TCP_Nagle = true;
     handler.HandshakeAndUpgrade();
 }
        private void HandlerOnOnText(object sender, WebsocketTextEventArgs text)
        {
            WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;

            obj.SendMessage(text.Data);
            m_log.Info("[WebSocketEchoModule]: We received this: " + text.Data);
        }
 public void UnSubscribeToEvents(WebSocketHttpServerHandler handler)
 {
     handler.OnClose            -= HandlerOnOnClose;
     handler.OnText             -= HandlerOnOnText;
     handler.OnUpgradeCompleted -= HandlerOnOnUpgradeCompleted;
     handler.OnData             -= HandlerOnOnData;
     handler.OnPong             -= HandlerOnOnPong;
 }
 //These are our normal events
 public void SubscribeToEvents(WebSocketHttpServerHandler handler)
 {
     handler.OnClose            += HandlerOnOnClose;
     handler.OnText             += HandlerOnOnText;
     handler.OnUpgradeCompleted += HandlerOnOnUpgradeCompleted;
     handler.OnData             += HandlerOnOnData;
     handler.OnPong             += HandlerOnOnPong;
 }
        private void HandlerOnOnData(object sender, WebsocketDataEventArgs data)
        {
            WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;

            obj.SendData(data.Data);
            m_log.Info("[WebSocketEchoModule]: We received a bunch of ugly non-printable bytes");
            obj.SendPingCheck();
        }
        // Remove the references to our handler
        private void HandlerOnOnClose(object sender, CloseEventArgs closedata)
        {
            WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;

            UnSubscribeToEvents(obj);

            lock (_activeHandlers)
                _activeHandlers.Remove(obj);
            obj.Dispose();
        }
Esempio n. 7
0
        private void HandleNewClient(string servicepath, WebSocketHttpServerHandler handler)
        {
            Connection conn = new Connection(new WSConnectionWrapper(handler));

            conn.LoadIDL("http://yellow.cg.uni-saarland.de/home/kiara/idl/interface.kiara");
            conn.LoadIDL("http://yellow.cg.uni-saarland.de/home/kiara/idl/connectServer.kiara");
            conn.RegisterFuncImplementation("omp.interface.implements", "...",
                                            (Func <string, bool>)InterfaceImplements);
            conn.RegisterFuncImplementation("omp.connect.useCircuitCode", "...",
                                            (Action <UInt32, string, string>)((code, agentID, sessionID) =>
                                                                              ConnectUseCircuitCode(conn, code, agentID, sessionID)));
        }
 public void WebSocketHandler(string method, WebSocketHttpServerHandler handler)
 {
     m_Handler                     = handler;
     m_Handler.OnClose            += Handler_OnClose;
     m_Handler.OnText             += Handler_OnText;
     m_Handler.OnUpgradeCompleted += Handler_OnUpgradeCompleted;
     m_Handler.OnData             += Handler_OnData;
     m_Handler.OnPing             += Handler_OnPing;
     m_Handler.OnPong             += Handler_OnPong;
     m_Handler.SetChunksize(8192);
     m_Handler.NoDelay_TCP_Nagle = true;
     m_Handler.HandshakeAndUpgrade();
 }
Esempio n. 9
0
        public void HandleWebSocketLoginEvents(string path, WebSocketHttpServerHandler sock)
        {
            sock.MaxPayloadSize    = 16384; //16 kb payload
            sock.InitialMsgTimeout = 5000;  //5 second first message to trigger at least one of these events
            sock.NoDelay_TCP_Nagle = true;
            sock.OnData           += delegate(object sender, WebsocketDataEventArgs data) { sock.Close("fail"); };
            sock.OnPing           += delegate(object sender, PingEventArgs pingdata) { sock.Close("fail"); };
            sock.OnPong           += delegate(object sender, PongEventArgs pongdata) { sock.Close("fail"); };
            sock.OnText           += delegate(object sender, WebsocketTextEventArgs text)
            {
                OSD request = null;
                try
                {
                    request = OSDParser.DeserializeJson(text.Data);
                    if (!(request is OSDMap))
                    {
                        sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse()));
                    }
                    else
                    {
                        OSDMap     req      = request as OSDMap;
                        string     first    = req["firstname"].AsString();
                        string     last     = req["lastname"].AsString();
                        string     passwd   = req["passwd"].AsString();
                        string     start    = req["startlocation"].AsString();
                        string     version  = req["version"].AsString();
                        string     channel  = req["channel"].AsString();
                        string     mac      = req["mac"].AsString();
                        string     id0      = req["id0"].AsString();
                        UUID       scope    = UUID.Zero;
                        IPEndPoint endPoint =
                            (sender as WebSocketHttpServerHandler).GetRemoteIPEndpoint();
                        LoginResponse reply = null;
                        reply = m_LocalService.Login(first, last, passwd, start, scope, version,
                                                     channel, mac, id0, endPoint, false);
                        sock.SendMessage(OSDParser.SerializeJsonString(reply.ToOSDMap()));
                    }
                }
                catch (Exception)
                {
                    sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse()));
                }
                finally
                {
                    sock.Close("success");
                }
            };

            sock.HandshakeAndUpgrade();
        }
 public void Shutdown()
 {
     m_Handler.OnClose            -= Handler_OnClose;
     m_Handler.OnText             -= Handler_OnText;
     m_Handler.OnUpgradeCompleted -= Handler_OnUpgradeCompleted;
     m_Handler.OnData             -= Handler_OnData;
     m_Handler.OnPing             -= Handler_OnPing;
     m_Handler.OnPong             -= Handler_OnPong;
     if (m_Handler != null)
     {
         m_Handler.Dispose();
         m_Handler = null;
     }
     if (activeHandler != null)
     {
         activeHandler.Dispose();
         m_Handler = null;
     }
 }
        private void Handler_OnUpgradeCompleted(object sender, UpgradeCompletedEventArgs completeddata)
        {
            activeHandler = sender as WebSocketHttpServerHandler;
            var handler = OnOverlayConnected;

            if (handler != null)
            {
                handler(this, activeHandler.GetRemoteIPEndpoint().ToString());
            }

            foreach (var key in m_ModuleCSS.Keys)
            {
                ComposeCssAdditionMessage(key, m_ModuleCSS[key]);
            }
            foreach (var key in m_ModuleJS.Keys)
            {
                ComposeJSAdditionMessage(key, m_ModuleJS[key]);
            }
        }
Esempio n. 12
0
        // Shutting down..  so shut down all sockets.
        // Note..    this should be done outside of an ienumerable if you're also hook to the close event.
        public void Close()
        {
            if (!enabled)
            {
                return;
            }

            // We convert this to a for loop so we're not in in an IEnumerable when the close
            //call triggers an event which then removes item from _activeHandlers that we're enumerating
            WebSocketHttpServerHandler[] items = new WebSocketHttpServerHandler[_activeHandlers.Count];
            _activeHandlers.CopyTo(items);

            for (int i = 0; i < items.Length; i++)
            {
                items[i].Close(string.Empty);
                items[i].Dispose();
            }
            _activeHandlers.Clear();
            MainServer.Instance.RemoveWebSocketHandler("/echo");
        }
Esempio n. 13
0
        private void HandlerOnOnUpgradeCompleted(object sender, UpgradeCompletedEventArgs completeddata)
        {
            WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;

            _activeHandlers.Add(obj);
        }
 private void Handler_OnUpgradeCompleted(object sender, UpgradeCompletedEventArgs completeddata)
 {
     activeHandler = sender as WebSocketHttpServerHandler;
 }
Esempio n. 15
0
 public WSConnectionWrapper(WebSocketHttpServerHandler handler)
 {
     m_handler = handler;
 }