Tutorial Week 10 ---------------- This week I covered sockets. I talked about the basic socket functions and described the basics of TCP (and even DNS). What to cover ------------- I'd like you to go through the basic inetserver.c and inetclient.c examples from http://www.cdf.utoronto.ca/~csc408h/winter/examples/sockets/index.html (There is also a makefile there) It would probably be a good idea to write each piece on the the board as you talk about it. They haven't seen any examples yet. - review what each of the socket functions does. (Maybe get them to tell you how to write this part.) - point out which file descriptors are used for what. - point out the use of htons for translating byte order of the port. - explain gethostbyname - explain setsockopt for the particular arguments. - If we don't run get setsockopt this way, then when we close the connection, and try to run our program immediately, we won't be able to use the same port, because the OS keeps the port assignment around for a while in case a client hasn't noticed that the connection is closed yet. (It's a little like zombie processes.) - We don't want to have to wait for the OS to give up the port, so setsockopt allows us to reuse it immediately. - point out which function might block (connect, accept, read) - remind them that when you read and write you need to worry about the number of bytes you are sending a receiving. You might want to change the reading and writing into a loop or having it transfer more interesting data.