Prev Up Next
Go backward to Berkeley Socket System Calls
Go up to Top
Go forward to APPENDIX A: A Simple Client

A Simple Client-Server Example and Exercises

We illustrate the TCP/IP protocol under Berkeley sockets. The following C programs (under unix) includes a simple server that waits at port 1234. The server is iterative. The client reads a number N (unsigned integer or float) from the user, and sends it to the server. The server sends back 2N which the client prints. This is repeated until the user types "quit".

Here is the client program.

Here is the server program.

Thanks to Ting-jen Yen for providing this example.

Chen Li has provided a Java-based version of this client-server program at <a href=http://cs.nyu.edu/ chenli/doc/ta/client_server_Java/> http://cs.nyu.edu/ chenli/doc/ta/client_server_Java/ </a>

EXERCISE: Construct a similar client-server program using UDP/IP.

EXERCISE: Perform measurements to determine the packet loss rate in your UDP/IP protocol.

EXERCISE: (a) Modify the Doubling client-server into one that can send and receive packages of data, and for each packet attach a time sent and received.
(b) Suppose we want to send 100 MB of data to some remote host. Determine the optimal packet size S so as to maximize the throughput T. The experiment must be repeated over a variety of network conditions (time of day). Is S a function of the network conditions (a parameter you may measure). (We will help arrange the remote setup - alternatively access NYU remotely from your modem.)
(c) In visualization, we also want to ensure the most predictable flow of data. What the the optimal S and T, subject making this transmission delay as consistent as possible?

EXERCISE: Modify Homework 1 (rotating color cubes) into a client-server framework. That is, we want a client that displays the rotating cube, but the rendering is performed on the server side. The server sends the rendered buffer to the client who displays it. Upon receipt of an image, the client makes another request. The client requests to the server are one of the following:
(1) Rotate Outer Cube (x,y,x',y') (see HW1 for these parameters).
(2) Rotate Inner Cube (x,y,x',y').
(3) Update Image. This is in the absence of other user commands.
(4) Radio Button Command (spin, shading).
(5) Quit.

EXERCISE: Modify the previous program as follows: we now insert a wavelet transform step into the server side. If I0 is the image, let Ii be the i-th level resolution of I0. The client specifies a level k and this is the initial image that he receives. If the image I0 is not updated between requests, then subsequent requests only has to send the difference to improve the image from Ik to Ik-1, Ik-2, etc. Of course, if I0 is modified, the next image is goes back to level k. So, for spinning cubes, we only get low level images. But for stationary cubes, the images gets progressively better.

EXERCISE: Extend the previous exercise to allow foveation.


Chee Yap

Prev Up Next