Computing 205/406 & IT8

Tutorial #6

  1. What is a socket? In what ways is a socket different from a file under Unix? In what ways is it similar?

  2. Are sockets the only conceivable way in which TCP connections can be managed? Why are they so commonly used?

  3. In the lecture, it was stated that the bind() system call was not normally needed in client software. Why not? Why is it needed for a server?

  4. All of the Unix socket-related system calls are C functions, that is, they always return a valueFor those functions for which the return values weren't specified (eg, bind(), connect(), listen()), what do you (as an experienced C programmer) think they would return. Check the man page for each to see if you're right.

  5. The read() system call specifies a maximum number of bytes which may be read from a socket. Do you think it can return less than this? Under what circumstances? What if the write() system call returned a different value from that given in its length argument?

  6. One for the serious C programmers: give a typedef which will define the sockaddr structure described in the lecture. This may be harder than it seems...

  7. (Very difficult question) The last slide made brief mention of the way in which the accept() system call returned a new socket. How is this used, and why is it a pretty nifty trick? Note: the answer is not at all obvious?

Practical exercises:


This tutorial is also available in PostScript format.
Phil Scott