Using Socket class for a simple client.

The client Socket class uses a SocketImpl to implement the actual socket operations. It allows to change socket implementations (if we need to) by setting the SocketImplFactory depending on the kind of firewall used. The main job of Socket constructors is to create a stream socket and connect it to the specified port on the specified host. close() method of Socket class closes the socket. /** * Here is an example of a simple client * connecting to the server via sockets. * The connection can be used to send * one command and receive one response. * * All the operation should be inside try - catch statements * as any Input/Ouput operation. * * We create a socket object with the specified host * (server name or IP address) * and the specified port number. * * We create Input and Output streams connected to the socket. * * We send array of bytes to the server and * receive array of bytes in response from the server. * * Then we close the streams and close the socket connection. * Done ! **/ Back To Java Networking