I'm building a server that just accepts client messages, so basically a subset of the first link's example. I am developing in eclipse. I ran this project and the program hangs when the server socket tries to accept a connection; why?
and here is my test program, the client which sends messages to the server:
Actually, you have a deadlock. Your program is waiting on itself.
In the constructor of your server, you're accepting client sockets. Bad idea. accept() is a blocking operation, and will wait until a client tries to connect. So your constructor waits for a client to connect, but this never happens because the constructor doesn't finish running.
You should use handlers in separate threads to deal with incoming connections.