Try Firefox!

Lab 13: A sockets version of the bc labs


Overview
Write a program named fna in a C source code file named fna.c. fna is a client program that communicates with a server running on a host named on the command line that is listening on a port also named on the command line. This version of fna behaves just like the fna program of Lab 9, except that a single duplex TCP socket is used for communication between processes instead of two one-way pipes.

For testing purposes, a bc server will be running on the host named bear.cs.usna.edu, listening on port 34567.

Also, you do not need to start from scratch: start with this skeleton version of fna.c. READ THE SOURCE CODE CAREFULLY AND FOLLOW THE COMMENTS!

Details
Here's what a correct solution of the lab looks like when executed.
banshee$ fna bear.cs.usna.edu 34567 ← we specify the host+port for the bc_server
2*x
0 4 8
4.000000
x^2+5*x-10
1 8 8
38.000000
s(x)
0 3.14 30
0.615136
^C
		    

Notice that program behavior is identical to Lab 9! The only thing that will have changed is that the process running bc will be located on a separate host and communication will be via sockets instead of pipes. This new version will require the user to specify the name of a host on which a bc server is running, as well as a port number to connect to.

Here are some additional examples of how your fna program should behave when it is used incorrectly, i.e. when it encounters some sort of error:

banshee$ fna
Usage: fna <hostname> <port>
banshee$ fna chessie
Usage: fna <hostname> <port>
banshee$ fna cheesy 34567
Couldn't get host entry.
banshee$ fna chessie 345
connect() error.
banshee$ fna chessie 34567
socket() error.
banshee$ fna chessie 34567
sigaction() error.
		    

Submission instructions
Make sure your submission is in a directory named lab13, and that it contains your completed fna.c file. Make sure that file contains your name and alpha! Submit the lab13 directory via the usual submit script. If you finish during lab, please demonstrate your working program to your instructor.


Christopher W Brown
Last modified: Wed Apr 15 23:21:37 EDT 2009