private void UpgradeWebSocket(IChannel channel, Request request) { var response = new Response { Status = 101, Protocol="1.1"}; var protocol = channel as IKeepProtocolChannel; if (protocol == null) return; var finder = GetWebSocketUriFinder(request); if (finder == null) return; var handler = channel as IKeepHandlerChannel; if (handler == null) return; handler.SetHandler((IChannelHandler)finder.GetHandler(request.GetPath())); response.GetHeader().AppendLine("Upgrade: websocket") .AppendLine("Connection: Upgrade") .AppendLine("Sec-WebSocket-Accept: " + GetWebSocketAcceptCode(request.GetHeader("Sec-WebSocket-Key"))); channel.SendMessage(response); protocol.SetProtocol(WebSocketProtocol.Protocol); handler.GetHandler().Connected(channel); }
private void UpgradeWebSocket(IChannel channel, Request request) { var response = new Response { Status = 101, Protocol="1.1"}; var finder = GetWebSocketUriFinder(request); if (finder == null) return; channel.SetConfig("handler", finder.GetHandler(request.GetPath())); //((IChannelHandler)channel.GetConfig("handler")).GetHandler(); response.GetHeader().AppendLine("Upgrade: websocket") .AppendLine("Connection: Upgrade") .AppendLine("Sec-WebSocket-Accept: " + GetWebSocketAcceptCode(request.GetHeader("Sec-WebSocket-Key"))); channel.SendMessage(response); channel.SetConfig("encoder", Protocol.PacketEncoder.WebSocket.WebSocketEncoder.Encoder); channel.SetConfig("decoder", Protocol.PacketEncoder.WebSocket.WebSocketDecoder.Decoder); //protocol.SetProtocol(WebSocketProtocol.Protocol); ((IChannelHandler)channel.GetConfig("handler")).Connected(null/**/); //handler.GetHandler().Connected(channel); }