When we talk of sockets, we are referring to both the TCP and the UDP socket. A socket connection is nothing but a combination of the IP address and the port number. Every service that we can think of that runs on a port implements and uses sockets internally.
For example, our web server, which always listens on port 80 (by default), opens a socket connection to the outside world and binds to the socket with the IP address and the port 80. The socket connection can be used in the following two modes:
- Server
- Client
When the socket is used as a server, the sequence of steps that the server performs is as follows:
- Create a socket.
- Bind to the socket.
- Listen at the socket.
- Accept connections.
- Receive and send data.
On the other hand, when the socket connection is used as a client to connect to a server socket, the sequence of steps is as follows:
- Create...