0
votes

I'm writing a game server in Java, and I'm using Netty 3.6.2. The game servers should accept no HTTP requests, as they simply handle game client data (which is purely bytes over TCP). When I load http://server-ip:game-servers-port in Chrome, I download a file with the game's handshake packet (which should not happen).

I bind to the game server's port like so:

ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
clientAcceptor = new ServerBootstrap(factory);

clientAcceptor.setOption("child.tcpNoDelay", true);
clientAcceptor.setOption("child.keepAlive", false);

clientAcceptor.setPipelineFactory(() -> Channels.pipeline(new PacketDecoder(), new ClientHandler()));

clientAcceptor.bind(new InetSocketAddress(Configurations.CHANNEL_GAME_PORT));

And I process requests in a SimpleChannelHandler, like so

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
    // Encryption key code.

    Packets.sendHello(ctx.getChannel(), ivRecv, ivSend);

    ctx.getChannel().setAttachment(client);
}

How can I go about deciphering if an incoming request is using the HTTP protocol?

Edit: I should also say, it should also block any FTP, WebSocket, etc. protocol (essentially anything that isn't the game's protocol) on channel connect.

1
The HTTP protocol is described in detail in it's RFC tools.ietf.org/html/rfc2616Gerald Schneider

1 Answers

2
votes

You can't expect to be able to disable HTTP requests if the first thing you do with an accepted connection is to send something.

Have the client do the first send in the handshake. Have the server start by doing a receive, and if it isn't the correct initial handshake packet, close the connection.