November 2006
Intermediate to advanced
224 pages
3h 29m
English
public static final short PORT = 9988; ServerSocket server = new ServerSocket(PORT); while ((clientSock = server.accept( )) != null) { // Process client request } |
In this phrase, we use a ServerSocket instance to create a server listening on port 9988. We pass the port that we want the server to listen on to the constructor of the ServerSocket. Once the server socket is created, we call the accept() method to wait for a client connection. The accept() method blocks until a connection with a client is made. When a client connection is made, a new Socket instance is returned.
If a security manager is being used, the security manager’s checkAccept() method is called with clientSock.getInetAddress().getHostAddress() ...
Read now
Unlock full access