A TCP Echo Server
Now we'll look at a simple TCP server. In contrast to a TCP client, a server does not usually call connect(). Instead, a TCP server follows the following outline:
Create the socket. This is the same as the corresponding step in a client.
Bind the socket to a local address. A client program can let the operating system choose an IP address and port number to use when it calls connect(), but a server must have a well-known address so that clients can rendezvous with it. For this reason it must explicitly associate the socket with a local IP address and port number, a process known as binding. The function that does this is called bind().
Mark the socket as listening. The server calls the listen() function to warn the operating ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access