Computing 205/406 & IT8
Tutorial #6
- What is a socket? In what ways is a socket different from a file under
Unix? In what ways is it similar?
- Are sockets the only conceivable way in which TCP connections can be
managed? Why are they so commonly used?
- 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?
- 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.
- 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?
- 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...
- (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:
- On ironbark, look at /usr/local/pub/C205 for some sample code for
manipulating sockets. Copy it your directory and try it out.
- For the experienced C++ programmers in the class: investigate the
socket++ libraries on ironbark.
This tutorial is also available in PostScript format.
Phil Scott