Skip to content

Instantly share code, notes, and snippets.

@chirino
Created February 11, 2014 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chirino/8936409 to your computer and use it in GitHub Desktop.
Save chirino/8936409 to your computer and use it in GitHub Desktop.
public void handle(final NetSocket socket) {
socket.dataHandler(new Handler<Buffer>() {
Buffer received = new Buffer();
@Override
public void handle(Buffer event) {
received.appendBuffer(event);
LOG.info("Received a buffer, matching protocols against: " + received.length());
for (final Protocol protocol : protocols) {
if( protocol.matches(received) ) {
protocol.snoopConnectionParameters(socket, received, new Handler<ConnectionParameters>() {
@Override
public void handle(ConnectionParameters connectionParameters) {
// this will install a new dataHandler on the socket.
route(socket, connectionParameters, received);
}
});
return;
}
}
if( received.length() >= maxProtocolIdentificationLength) {
LOG.info("Connection did not use one of the enabled protocols "+getProtocolNames());
socket.close();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment