CS 337 Programming Examples

  1. Cnet examples

  2. New client/server examples. The following are C++ versions of the old stuff that's described in detail below. These new versions are modularized a bit differently, and they also include code to give the client and servers command line arguments. For example, to run the server, you'd type "helloServer 1234 Howdy" to start the server at port 1234 with message "Howdy". To see usage statements, run the programs without any command line arguments.

    Questions and suggestions are welcome.



  3. Example client/server code. Do not represent this code as good template code for industrial-strength client/server programs. This code is pedagogically oriented, and thus I have made some dramatic simplifications that you would not want to make if you were developing software for long-term use. I'll talk about these simplifications in class.

    Test this code as follows. First, go into hello.h and change HOST_NAME to the name of whatever machine you're working on. Then compile two servers and a client.

    Next, open two terminal windows. In one, start iterativeHelloServer running. Then, run helloClient in the other window. The server should report the connection in the server window, and the client should report the message it received from the server in the client window. The client will quit on its own, but the server will keep running. You can shut down the server with a CTRL-C in the server window.

    You can play the same game again with concurrentHelloServer and helloClient. But even after the iterativeHelloServer is no longer running, the port it had been listening to will be unavailable for a few minutes. So if concurrentHelloServer tells you "can't bind to 5554 port: Address already in use," just keep trying. Eventually the port will become available.





Jeff Ondich, Department of Mathematics and Computer Science, Carleton College, Northfield, MN 55057, (507) 646-4364, jondich@carleton.edu