Transmission Control Protocol (TCP) Sockets
00:11 The first is Transmission Control Protocol, TCP. Its important properties include that it’s reliable, meaning packets lost during transmission can be detected by the sender and resent, and the data is read by the receiver in the order it was sent, called in-order data delivery. The other protocol is User Datagram Protocol.
00:34 It uses less overhead since it doesn’t track for lost packets or similar issues, so it’s primarily used where speed of transmission is more important than reliability. Of these, TCP is the default protocol sockets use, and it’s the most frequently one used, mainly because it does try to react to lost packets.
00:59 Here’s a diagram showing the activities in the server and client processes and the timing of each relative to the other as data is sent and received. The server begins by creating a socket, binding it to a port, listening for client requests, and finally accepting one when one comes in.
01:18 That request happens when the client process creates a socket and requests a connection to the server. Then the client sends data indicating what it’s wanting from the server, which the server then receives.
01:32 The server then processes that incoming data with the request, performs the actions needed to return the data desired, then sends that to the client process, which then receives the data and uses it however it was intended.
This can be broken down into four phases. First, the server creates its listening socket. It does this with the creation of a socket, then using the
.listen(), and then, when requested,
.accept() method calls.
For its part, the client creates its own socket, then calls the
.connect() method to initiate a connection with the server. Then the two processes alternate sending and receiving data, and finally the connection is closed.
Become a Member to join the conversation.