February 2014
Beginner
1248 pages
62h 25m
English
In Step 1, we create a Socket to connect to the server. The Socket constructor establishes the connection. For example, the statement
Socket connection = new Socket(serverAddress, port);
uses the Socket constructor with two arguments—the server’s address (serverAddress) and the port number. If the connection attempt is successful, this statement returns a Socket. A connection attempt that fails throws an instance of a subclass of IOException, so many programs simply catch IOException. An UnknownHostException occurs specifically when the system is unable to resolve the server name specified in the call to the Socket constructor to a corresponding IP address.
Read now
Unlock full access