CIS-3152 Homework #2 (Demonstrating Deadlock)

Due: Wednesday, January 29, 2018

In the text read in Chapter 5, sections 5.1 through 5.10. This covers concurrent TCP servers. Chapter 4 contains a lot of good material on the sockets functions we've talked about such as connect, accept, etc. Use Chapter 4 as a reference, but you might skim it over to see what's there in any case.

  1. There is a theoretical problem with the echo client/server pair presented in class. If the client tries to send an extremely long line the two programs will deadlock (both block waiting for each other). This can occur because the write on the client will not return until it has queued all the desired data for sending. As the server echos the data back to the client, the various network buffers will fill and, if there is too much data, write on the client will never complete.

    The purpose of this assignment is to demonstrate this effect. However, you don't have to solve the problem, although I encourage you to think about it. Modify the echo client so that instead of sending lines of text from the user it fills a large array with uninteresting data (for example, the letter 'x'). Make the array, for example, one megabyte in size. Try to write the entire array in one call to write. When you run your client against the server it should hang.

  2. Convince yourself that the client is actually doing something by modifying it again so that it writes the one megabyte buffer in 1024 byte pieces, printing a message just after writing each piece. Do not read any data from the server while doing this! How far does the client get before it hangs? This is an approximate measure of the size of all network buffers involved in the communication.

Submit your modified client to Moodle.

Last Revised: 2018-01-24
© Copyright 2018 by Peter C. Chapin <>