Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

SOCKETS ON LINUX

Any network, large or small, can use sockets. In this section, let’s look at some socket basics on Linux systems.

We could write socket client and server applications from scratch, but the truth is that programmers hate to write anything from scratch. Usually, they hunt around for code that does something pretty close to what they want and modify it for the occasion (at least for noncommercial purposes). There are plenty of socket examples available on the Internet, so we downloaded some code written by Michael J. Donahoo and Kenneth L. Calvert. The code, which comes with no copyright and a “use-at-your-own-risk” warning, is taken from their excellent book, TCP/IP Sockets in C (Morgan Kaufmann, 2001).

We’ll use TCP because there should be more efficiency derived from a connection-oriented, three-way handshake protocol like TCP than in a simple request–response protocol like UDP. This application sends a string to the server, where the server socket program bounces it back. (If no port is provided by the user, the client looks for well-known port 7, the TCP Echo function port.) First, we’ll list out and compile my version of the client socket code (TCPsocketClient and DieWithError.c) on lnxclient. (Ordinarily, we would put all this is its own directory.)


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint