June 2017
Beginner
1296 pages
69h 23m
English
Establishing a simple client in Java requires four steps.
Socket to Connect to the sServerIn 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 ...
Read now
Unlock full access