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:

  1. Create the socket. This is the same as the corresponding step in a client.

  2. 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().

  3. Mark the socket as listening. The server calls the listen() function to warn the operating ...

Get Network Programming with Perl now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.