Java – In Java or .NET, how would you create a server that listens to a specific port

javanet

In Java or .NET, how would you create a server that listens to a specific port?

(Just a dummy server, I just want to get the high level idea.)

Best Answer

Suggest Sun's Learning Trail tutorial on writing a client and server for Java.

The key code you need (copied from the above link) is:

ServerSocket serverSocket = null;
try {
    serverSocket = new ServerSocket(4444);
} catch (IOException e) {
    System.out.println("Could not listen on port: 4444");
    System.exit(-1);
}