I’m implementing a simple TCP client and TCP server in Java at the moment, and when searching for examples, I’ve stumbled across this nice Python framework:
http://docs.python.org/library/socketserver.html
EDIT
I’m looking for a solution where you can create a TCP-Server by doing a call like this:
TCPServer server = new TCPServer(port, RequestHandler);
server.serveForever();
So, I have a multihreaded server out of the box, where I only have to implement the RequestHandler (which could be some sort of interface requiring a handle method).
Is there something similar in Java? It seems to make implementing network servers very easy and straightforward.
Not in the core language, no. You have to do the normal things you would do in most languages where you set up the listener, accept connections, check for input, etc.
I’m sure somewhere someone has built a generic “framework” for this, but in all honestly, it’s about 40 lines of code and there’s umteen tutorials out there that show it.
The most analogous approach is using the java NIO classes (1.4 and above) and using the
Selectorto accept and poll for new connections and input on connected sockets.