what is computer network socket, how multiple sockets are used, what are the examples of network socket
NETWORK SOCKET
In this blog, we will discuss what is computer network socket? In every single transport layer connection, there is pair of ports: source port and destination port. In every single server, there could be many applications or processes launched and up and running.
If we look at this picture, the server needs to open these ports to be able to accept some segments that come from some other clients to this server. For example, port 443 should be opened on this server. But port 445 or 446 should be closed. And if someone attempts to send data for one of the closed ports. The server will reject such segment and the same relates to the client. The client should identify how it should process returned traffic that goes from the server back to the client and that is where network sockets come in.
A network socket is a host endpoint that is used for outgoing and incoming data. It consists of five fields and on every server and client network sockets must be present if they want to process some data and send them up to the application layer of the TCP/IP model. Network socket consists of five different fields: Transport protocol it could be either or TCP or UDP, Source IP address, Source port, Destination IP address, and Destination port. If there is a client and server, a client initiates the connection to the server then on the server side you will find a network socket where the source IP address and the source port will match to client's IP address and the client’s source port that was used for initiation of the connection. Destination IP address and destination approach match with IP address. A port on the server-side and the client-side for the same connection there will be also a network socket. But the source IP address and destination API address and port pairs will be reversed. On the client-side, destination IP address and destination port will match with IP address and port on client and source IP address with source port will represent IP address and port of remote server for specific TCP or UDP connection.
How multiple sockets are used?
In every single client or server may exist multiple sockets also you may see wildcard fields like wildcard the source IP address or wildcard source port or wildcard destination IP address. But the destination port is fixed and it is set to one of the well-known ports or ports from other ranges.
How a single server may keep
multiple sockets and how a server may serve multiple clients that connect to the
same destination port that is open on a specific server?
Assume that there is a
server with IP address 42.16.1.18 and that it listens to connections to TCP
port 443 and TCP port 993. These ports are well-known ports that are used by
two applications HTTPS and IMAPS secure correspondingly and these ports are TCP
ports. So these two protocols work over TCP.
Assume there are several
clients’ systems A and B, and one mobile phone and for example, the laptop has an
IP address. Now system A initiates TCP connection to destination IP address
42.16.1.18 and destination port 443. In this case, the initial connection will
be made to the wildcard socket that has a source IP address and source port set
to wildcard, and the state of this socket on the server listens. When system A
creates an initial connection server will create an additional new socket with
exact source IP address 21.5.1.10 and exact port 1028 was chosen by system A
client randomly and it is greater than 1024. Destination IP address and destination
port will be the same as wildcard socket that listens to incoming connections. After
that in socket A, client A will establish a TCP connection. Then TCP connection
will be established the client A and the server will exchange data over the
particular socket. In client A there will be also a new socket created and in
that socket source IP address port and destination IP address and port pairs will
be reversed. So destination IP will be equal to IP of system A and destination
approach will be equal to port 1028. Source IP and source port in the particular
socket on the client-side will be equal to these values that are configured on
the server-side. Next system B may initiate a connection to the same
destination port 443 the HTTPS protocol. But now the system B has a different
IP address and it initiates a connection transport layer connection from
another port. Let's assume the port is 1521 and the destination IP and
destination port are the same as wherein the connection from system A. Now
again first TCP segment will be sent to the socket with wildcard source IP and
source port. Afterward, the new socket will be created particularly for the specific
connection from system B with 150.3.5.20 IP address and port 1521, and afterward
when the TCP session will be established data will be sent over the dedicated
socket between system B and the server. And it means that now there are two different
sockets from two different systems that are created on the server-side and the destination
port for both sockets is the same 443. But now the server will understand where
to send specific data depending on the pair of IP addresses and ports for every
single socket.
Let's assume that there is one more device that wants to connect to the server and it initiates several connections to the same server. One connection is initiated from source port 1035 to destination port 443. Again separate socket will be created for the particular connection and then this phone creates two destination ports 993 and different mail applications want to send or download some emails on the same device on the same phone. It means there will be two different TCP connections but with different source ports 1035, 1045, 1081 from the device with the same IP address 18.4.100.15 of the mobile phone. Now on the server for this particular destination port 993 this IMAPS port, there will be three different sockets. The first one will be a wild card with wildcard source IP and source port. Another one for source IP 18.4.100.15 and source port 1045 and the third one for source IP 18.4.100.15 and the source port 1081 and that's how the server will understand where to send different TCP segments either to port 1045 or to port 1081 when data is sent from the server back to the client. Similarly, it will understand which socket to use when some segments come from IP address 18.4.100.15 it will look into ports 1045 and 1081 because they are different. In this particular example, there will be two wildcard sockets for every port every destination port 443 and 923. There will be three additional sockets for destination port 443 with exact source IP and source port. Also, there will be two additional sockets for port 993 because this phone has opened two different TCP connections from different applications.
Network Sockets Examples
In this first example, we
have protocol TCP, source IP address, source port it is larger than 1024. Because
when a client initiates the connection to the remote server it chooses any free
port that is larger than 1024, destination IP address, and destination port. In
this example, the destination port is 443 that is a well-known port and used by
the HTTPS protocol. The HTTPS protocol is used by such applications as Google Chrome,
Safari, Mozilla, etc. Also, the status or state of the specific socket and for TCP
you may find such states as established or listen. In this example, the TCP
session is considered as established. The socket has five different fields’ protocol,
source IP, source port, destination IP, and destination port, and additionally
state that is established in this case. This set of different fields fully represents
a specific socket. Let's assume that some client sends to the server IP packet
from the IP address 52.12.20.3 to the IP address 17.248.14.204 on the network
layer of the TCP model. This IP header is stripped and afterward, the server
looks into the transport layer header. And let's assume that there is protocol TCP
source port client support is 53212 and destination port is 443. In this case, the
server finds an existing socket and it understands that server should process
the specific IP packet from the client and every single socket is created by a specific
application or process on the server. In this case, the server will strip the transport
layer header and send inner data or payload to a specific application that has
created the corresponding process that handles the corresponding socket.
In the transport layer of the TCP model, the server will find the destination port
equal to let's say 500 and there is no such kind of socket that exists on the
server. Then such transport-layer segment will be silently discarded.
Next example, in this socket destination IP address and destination port are the same as the previous socket. But now source IP address and source port are a wildcard. It means that socket 2 will accept any segment that comes from any source IP address from any source port. But protocol must be TCP and that state of the network socket 2 listens. It means that this socket listens for incoming connections via TCP from any source IP address and any source port. The destination IP address is set to the IP address of the server itself and the destination approach is 443 that is the wildcard socket.
In this example, there was also a wildcard destination IP address which means that this particular network socket will listen to any TCP segments from any source IP address from any source port to any of the IP addresses configured on the server. Because the server may have multiple network connections it may have multiple network interface cards. But the destination port must be 8080 and we also at the server-side listen to any incoming segments on the transport layer. Those are sent to any IP address of the server and the destination port equal to 88.
Finally last example, this protocol UDP, source IP address, and source port are wildcard destination IP address is 8.8.8.8, and destination port is 53 it is a well-known port reserved by DNS protocol. And that's how the server may listen to incoming DNS requests that are sent to UDP port 53. For example, the first two sockets may exist on the server simultaneously what does it means that multiple connections may be established to the single same port that is open on the server.
Summary
Network socket or internet socket consists of five different fields’ protocol, source IP address, source port, destination IP address, and destination port five different fields. In every client or server, there may be multiple sockets created at any moment, and sources could be created and removed dynamically. That depends on which connections are established between pair of client and server.
 
 
							     
							     
							     
							     
 
 
 
COMMENTS