Reputation: 1611
I have been using Netty for a while but mainly for using normal sockets when their channels always unique, thus I can map channels to know who are connecting to my server.
Now I have managed to implement http communication. The problem is that values of ChannelHandlerContext handlers (and either channels from those handlers) are not unique, I cannot detect who are connecting just by their handlers.
Questions:
Is that behaviour (ChannelHandlerContext handler values not unique) normal or do I have some bugs in code?
Any idea, solution?
Many thanks
My ChannelInitializer looks like the following:
public class NettyHttpServerInitializer extends ChannelInitializer<SocketChannel> {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("http", new HttpServerCodec()));
pipeline.addLast("dechunker", new HttpObjectAggregator(65536));
pipeline.addLast("handler", new HttpServerHandler());
}
}
My server handler looks like (values of ctx and ctx.channel() are not unique even trigged from same client):
public class HttpServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
@Override
protected void messageReceived(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
...
}
}
Upvotes: 0
Views: 173
Reputation: 18834
When making a http protocol, a connection can be reused, that means that 1 connection can handle multiple requests. You should not the priciple of a connection is a person for your game, but you should use cookies or some sort of access token in your protocol.
Under normal circumstances, browsers will keep a maximum of 2 connections to the same ip.
Upvotes: 3