Assignment 2 FAQ, Tutorials, Errata, and Addenda
Last update: Wednesday, March 4, 2009 14:17 EST
- Some notes about the socketdemo code:
-
-
#include <stdlib.h>declares functions such as exit. SunOS and Linux generally don't complain if it's missing. OS X does. - I detect the SIGCHLD signal, which signals the death of a child process. Sun OS used SIGCLD but the POSIX name is SIGCHLD. Sun OS defines both of them to the same thing.
-
Neither Linux nor OS X have an ERESTART error (interrupted system call that needs to be restarted).
I have an
#ifndef ERESTART. You can usemake -f Makefile.linuxto compile it.
-
- How should the clients or server handle files that already exist with the same name in destination directory? Is this considered an error?
- You don't have to treat this as an error. You're welcome to overwrite them.
- Do the original and copied files have the same name?
- No. The client accepts two names on the command line. One is the file you open and the other is the name you send.
- Do optional parameters always come before the two file name parameters?
- Yes. This is the convention for Unix/Linux commands.
- Should the programs compile and run on specific machine(s) at Rutgers and software versions?
- They should run on the cereal systems and/or remus/eden/... . Most likely, they'll run on both. If they run on OS X (10.5) or Windows XP under cygwin, that will work as well since I'll be able to test them.
- Why do I need both local and remote filenames on the clients? Do servers need to know both names?
-
Only the client needs to know the local file name.
For the put client, the logic is as follows:
- open local file (local_filename)
- connect to the server.
- send the server the command "put
" - read a block of data from the local file
- send the block to the server
- repeat 4-5 until end of file
- close the connection
- close the local file.
- How do I test my program?
-
Test #1.
Run the server on some port, such as 23456:./server -p 23456
Telnet to the server on that port from another windowtelnet localhost 23456
Now you'll send commands to the server that mimic those that the client would send. For example:put testfile test 1 2 3 test 4 5 6
As soon as you hit enter after typing "put testfile" you should have received a line containing "ok".
Important Note: To close the connection, enter telnet command mode by typing control-] (control key together with the ']' key). You'll get a telnet prompt. Enter the command
closeto close the connection.Test #2
Try the same thing with get. Telnet to the server and send the message
get testfile
You should see "ok" followed by file data.Tests #1 and #2 test the server since you didn't touch your clients.
Test #3
Now do the same test with your real clients. Run:
put -h localhost -p 23456 testfile newfile
The server should create a file called newfile that is identical to testfile. You can compare with:
cmp testfile newfile
If cmp returns without telling you of differences then the files are the same.
Test #4
Try the same test with the get client. Run
get -h localhost -p 23456 newfile getfile
The client should create a file called getfile that is identical to newfile.
Tests #5 & #6
Make sure you can handle large binary files. For example, Run:
put -h localhost -p 23456 /bin/bash newfile
The server should create a file called newfile that is identical to /bin/bash. You can compare with:
cmp /bin/bash newfile
Run
get -h localhost -p 23456 newfile getfile
The client should create a file called getfile that is identical to newfile.
Remove newfile and getfile so you don't waste space!
Additional tests:
Test with non-existent files on the client and server. Test invalid command-line arguments. Etc.
- After we download/upload a file - the client disconnects and shuts down. But does the server reset to wait for another connection or does it also shut down?
- You should have it wait for another connection so that someone can run other get/put commands without restarting the server.
- How big do I make my buffer for sending chunks of the file?
- For starters, you don't want to make it the size of the file. What if the file is 20 GB in in size? Too big a buffer will cause the data to be fragmented into multiple packets. Too small a buffer may send smaller-than-maximum packets (unless Nagle's algorithm is on and the network is sufficiently slow). Normal IP packets have a maximum size of 1522 bytes (or 9220 bytes for jumbo frames) but this doesn't include ethernet, IP, and TCP header overhead. Using any number between, say, 2048 and 8192 should be fine.
- How come the file that gets created is an executable file?
-
You can specify the mode of the file that you're creating as the
third parameter to the open system call. For example, using
open(filename, (O_CREAT | O_WRONLY | O_TRUNC)), 0644)
will create a file with read/write permissions for the owner and read permissions for others (see man 2 open and man 2 chmod).