Refactor the TCP specific handling out into a separate handler, specify the connection type in the listener and use generics with the server listener so that other protocols such as UDP and multicast can be supported by plugging them in without doing any specialized handling in the common framework.