Building Socket Programs


Sample code: the sample tarball contains a Makefile and code for a simple server and its corresponding client. The Makefile works as is for Linux and Mac OS X. The server keeps count of how many times it has been contacted by the client. It waits for connection and when a client connects, it sends back a message with the contact count. The client contacts the server, which has been hardcoded to be running on the same host as the client ("localhost"), receives the server's contact count and prints it out. Both server and client have run on Linux, Mac OS X, and Windows platforms. In the following, we show only how to build a server using the file server.c. You can follow an analogous set of steps to build a client using the file client.c. (But don't include both source files into a single project!)

To find out how to specify command line options, add to header file search path, and link with 3rd-party libraries, see the course note on these topics.

Please let me know if you have any correction or addition. Thanks.


version: Ubuntu 12.10
gcc: 4.7.2
Eclipse 3.8.0 (Juno)
version: Red Hat Enterprise Linux Server release 6.4 (Santiago)
gcc: 4.4.7
Eclipse 3.6.1 (Helios)

Mac OS X:

version: Mavericks 10.9.1
kernel: Darwin 13.0.0
Xcode: 5.0.2
gcc: 4.2.1


version: 10 Enterprise; 8.1 Enterprise; 7 Enterprise
Visual Studio Enterprise 2015 v. 14.0.24720.00 Update 1; Visual Studio 2013 v. 12.0.31101.00 Update 4; 2012 v. 11.0.51106.01 Update 1
.NET Framework v. 4.6.01055; 4.5.51650; 4.5.50709

References not cited:

Last updated: Jan. 26, 2016 by Sugih Jamin