protected override void Decode(IChannelHandlerContext ctx, IHttpRequest msg, List <object> output) { try { string uri = msg.Uri; switch (uri) { case "/handshake": var connectionInfo = channelGroup.FindConnectionInfo(ctx.Channel); if (connectionInfo == null) { channelGroup.Add(new ConnectionInfo(ctx.Channel, this.Options)); } ctx.Channel.Pipeline.FireUserEventTriggered(new HandShakeEvent()); break; default: var message = messageFactory.Parse(uri); if (message != null) { output.Add(message); } break; } } finally { ReferenceCountUtil.Release(msg); } }
protected override void ChannelRead0(IChannelHandlerContext ctx, IChannel child) { var connectionInfo = channelGroup.FindConnectionInfo(child); if (connectionInfo == null) { channelGroup.Add(new ConnectionInfo(child, this._options)); } ctx.FireChannelRead(child); }
protected override void ChannelRead0(IChannelHandlerContext ctx, DatagramPacket msg) { var message = messageFactory.Parse(msg.Content); if (message == null || int.Parse(message.Headers.Get(Constants.Headers.ContractId)) != (int)ContractType.HandShake) { return; } IChannel child = new UdpSocketDatagramChannel(ctx.Channel, msg.Sender); var connectionInfo = channelGroup.FindConnectionInfo(child); if (connectionInfo == null) { channelGroup.Add(new ConnectionInfo(child, this._options)); } ctx.FireChannelRead(child); }
protected override void Decode(IChannelHandlerContext ctx, IFullHttpRequest req, List <object> output) { // Handle a bad request. if (!req.Result.IsSuccess) { SendHttpResponse(ctx, req, new DefaultFullHttpResponse(Http11, BadRequest)); return; } // Allow only GET methods. if (!Equals(req.Method, HttpMethod.Get)) { SendHttpResponse(ctx, req, new DefaultFullHttpResponse(Http11, Forbidden)); return; } // Handshake var wsFactory = new WebSocketServerHandshakerFactory( GetWebSocketLocation(req), null, true, 5 * 1024 * 1024); var handshaker = wsFactory.NewHandshaker(req); if (handshaker == null) { WebSocketServerHandshakerFactory.SendUnsupportedVersionResponse(ctx.Channel); } else { handshaker.HandshakeAsync(ctx.Channel, req); } ctx.GetAttribute(wshsKey).Set(handshaker); var connectionInfo = channelGroup.FindConnectionInfo(ctx.Channel); if (connectionInfo == null) { channelGroup.Add(new ConnectionInfo(ctx.Channel, this.Options)); } ctx.Channel.Pipeline.FireUserEventTriggered(new HandShakeEvent()); }