91-9990449935

 0120-4256464

Socket Programming:

Socket programming is performed for communication between the machines. Socket programming can be connection-oriented or connectionless. Socket and ServerSocket classes are used for connection-oriented socket programming. The client in socket programming must know two information:
  1. IPaddress of Server, and
  2. Port number.

Socket class:

A socket is simply an endpoint for communications between the machines. The Socket class can be used to create a socket.

Commonly used methods of Socket class:

1) public InputStream getInputStream()
2) public OutputStream getOutputStream()
3) public synchronized void close()

ServerSocket class:

The ServerSocket class can be used to create a server socket. This object is used to establish communication with the clients.

Commonly used methods of ServerSocket class:

1) public Socket accept()
1) public InputStream getInputStream()
2) public OutputStream getOutputStream()
3) public synchronized void close()

Example of Socket Programming:

To execute this program open two command prompts and execute each program at each command prompt as displayed in the below figure.
Networking
Next TopicURL class