Chapter 6 introduces the student to the details of
socket programming. In Experiment 6.1 they are
asked to obtain sample code from Purdue University.
As in Chapter 5 you may wish to do this for them
and provide a local copy.
In Experiment 6.2 students rewrite the version
of echo software provided in Chapter 5 to
eliminate the simplified API. I found it much
easier to modify client.c
and
server.c
provided in this chapter.
I also chose (or was it just a dumb mistake)
to implement chat
rather than
echo
. That was felicitous since
it gave me the opportunity to modify it
to satisfy the specifications of the second
Optional Extension in Experiment 5.2.
Experiment 6.4 is a good introduction to the differences
between the two main protocols, tcp and udp. It is important
since Chapter 8, which I use as the semester project, is
done using udp.
When we went over Chapter 27 in Computer
Networks, we spent some time trying to work out a procedure
for converting a client/server suite from tcp to udp.
That procedure turned out to be very helpful in last year's lab
on this topic, and
following it let me make the conversion without
having worked through it ahead of time and without notes.
Next time around they will do it themselves with the following
directions:
For both client and server:
- change the string "tcp" to "udp".
- change SOCK_STREAM to SOCK_DGRAM.
- eliminate receive loops in favor of a simple
recv
call.
- Server:
- Take out the calls to
listen
and
accept
.
- Change
send
to sendto
and recv
to recvfrom
.
Client:
You do not have to make any additional changes to the client,
but you may remove the connect
call if you
change send
to sendto
and recv
to recvfrom
.
It might be a good strategy not to give them that last step.
They will then encounter the following behavior:
the client will be able to contact the server,
but the server's response will not get to the client.
If they think this through,
they should see that without a connection and with the server not
saving the client's ip address and port number, the behavior
they encounter is exactly what they should have
expected.
This site is maintained by W. David Laverell
of the Computer Science Department
at Calvin College. For assistance or corrections,
please contact him at .