コード例 #1
0
 public virtual void AttachSession(WebSocketSessionBase session)
 {
     if (session != null)
     {
         base.SetSession(session);
         SessionCreated(session);
     }
 }
コード例 #2
0
 public virtual void DettachSession(WebSocketSessionBase session)
 {
     if (session != null)
     {
         session.MessageReceived    -= ws_MessageReceived;
         session.SwitchingProtocol  -= ws_SwitchingProtocol;
         session.HandshakeCompleted -= ws_HandshakeCompleted;
         RemoveSession(session);
     }
 }
コード例 #3
0
        public override void SessionCreated(Dynamic.Net.Base.INetSession session)
        {
            base.SessionCreated(session);
            WebSocketSessionBase ws = session as WebSocketSessionBase;

            if (ws != null)
            {
                ws.MessageReceived    += new EventHandler <MessageReceivedEventArgs>(ws_MessageReceived);
                ws.SwitchingProtocol  += new EventHandler <SwitchingProtocolEventArgs>(ws_SwitchingProtocol);
                ws.HandshakeCompleted += new EventHandler(ws_HandshakeCompleted);
            }
        }
コード例 #4
0
        void sendHandshakeCommand(Socket socket)
        {
            if (socket.Connected)
            {
                try
                {
                    string url = this.Url;
                    if (String.IsNullOrEmpty(url))
                    {
                        url = "/chat";
                    }
                    string header = String.Format(@"GET " + url + @" HTTP/1.1
Host: {0}
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: {1}
Sec-WebSocket-Protocol: {2}
Sec-WebSocket-Version: 13

", Host, Origin, Protocols);

                    session             = sessionFactory.CreateSession(this, protocol, client);
                    session.SubProtocol = Protocols;


                    session.MessageReceived    += new EventHandler <MessageReceivedEventArgs>(session_MessageReceived);
                    session.SessionClosed      += new EventHandler(session_SessionClosed);
                    session.HandshakeCompleted += new EventHandler(session_HandshakeCompleted);

                    session.Start();

                    socket.Send(Encoding.UTF8.GetBytes(header));
                }
                catch
                {
                    lock (lockerObj)
                    {
                        isConnecting = false;
                    }
                    if (Connected != null)
                    {
                        Connected(this, new WebSocketConnectedEventArgs(false, this));
                    }
                }
            }
        }