Computer Networks
Tutorial #6
- What is a socket? In what ways is a socket different from a file under
Unix? In what ways is it similar? Why are these differences and similarities
historically important?
- 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? NB: What this question is asking, in part, is what bind()
actually does - if you understand this, you should know
the answer.
- When[1] is the
listen()
call important?
- 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?
- (Very difficult question[2]) The second
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:
- The example code in the lecture uses
getservbyname()
to
map well-known services to port numbers. How is this performed on
your generic Unix box? What about on other systems?
- The example client code given in the lecture is a cut-down version
of this program. Save the program source code
from your browser and try compiling and executing it. Change the port
number to 80, for HTTP, and modify the string sent to the server so
this program can be used for "Web page fetching".
- On ironbark, look at
/usr/local/pub/BITCNE
for some more
sample code for manipulating sockets. Copy the example there to your
directory and try it out.
- For the experienced C++ programmers in the class: investigate the
socket++ libraries on ironbark.
[1] From Comer, P363.
[2] Seriously. You are not expected to understand this for
this subject. However, people who have already taken a subject
such as System Software will see what's going on here.
[Previous Tutorial]
[Tutorial Index]
[Next Tutorial]
Phil Scott