Ejemplo n.º 1
0
        public void CreateHandler(IEnumerable <byte> data)
        {
            byte[] bytes   = data.ToArray();
            var    request = RequestParser.Parse(bytes, owner.Schema);

            if (request == null)
            {
                return;
            }
            handler = WebSocketHandlerFactory.BuildHandler(request, SockectConnection.OnMessage, SockectConnection.OnClose, SockectConnection.OnBinary);
            if (handler == null)
            {
                return;
            }
            var subProtocol = SubProtocolNegotiator.Negotiate(owner.SupportedSubProtocols, request.SubProtocols);

            ConnectionInfo = WebSocketConnectionInfo.Create(request, SockectConnection.Socket.RemoteIpAddress, SockectConnection.Socket.RemotePort, subProtocol);

            if (!string.IsNullOrEmpty(ConnectionInfo.Path))
            {
                SockectConnection.Session.Add("WebSocket_Path", ConnectionInfo.Path);
            }

            foreach (string item in ConnectionInfo.Cookies.Keys)
            {
                SockectConnection.Session.Add(item, ConnectionInfo.Cookies[item]);
            }

            var handshake = handler.CreateHandshake(subProtocol);

            SockectConnection.RawSend(handshake);
        }