 (selectedPort) /* define domain name (address) * / hptr = gethostbyname ("address") ; memcpy ( (char*) &remoteAddr.sin_addr.s_addr hptr->h_addr list [0], hptr->h_length) , memset (buf, 0, DATABUF) ; remoteAddrLen = sizeof (remoteAddr); / No need to bind if communication is not peer-to-peer * / while (gets (buf) ) Socket Communication /* send information to server * / sendto (socketID, buf, sizeof (buf), , 0, &remoteAddr, sizeof (remoteAddr) ) ; memset (buf, 0, sizeof (buf) ) ; /* receive information from server * / recvfrom (socketID, buf, DATABUF, 0, &remoteAddr, &remoteAddrLen) ; printf ("%s\n", buf) ; memset (buf, 0, sizeof (buf) ) ; } /* end of while loop * / /* Close the socket connection * / close (socketID) ; 26.9 Conclusion Most legacy developments on NMS are client-server based and these solutions usually use socket communication for interaction. In the client-server model only when intermittent communication is involved the transmission mechanism is UDP based and when a continuous reliable connection is required, TCP is used. This chapter gives the reader a basic understanding of socket programming by introducing the reader to the basic terminologies. The sample code given in this chapter is intended to bridge the gap between theory and implementation, by first explaining the program and then supplementing the discussion with code. Comments have been added in the code, SO that the reader can easily follow the program execution. Additional Reading 1. Lincoln D. Stein. Network Programming with Perl. United Kingdom: Addison-Wesley Professional, 2001. 2. W. Richard Stevens, Bill Fenner, and Andrew M. Rudoff. Unix Network Programming, Volume 1: The Sockets Networking API. 3rd ed. United Kingdom: Addison-Wesley Professional, 2003. 3. Elliotte Rusty Harold. Java Network Programming. 3rd ed. California: O'Reilly Media Inc., 2009. 4. Michael Donahoo and Kenneth Calvert. TCP/IP Sockets in C: Practical Guide for Programmers. San Francisco, CA: Morgan Kaufmann, 2000. 5. Richard Blum. C# Network Programming. Sybex,