FAQ for Assignment 2: [Last Update: 10/17/2000 5 PM] 1. How to compile sample code? A: If you use "gcc" instead of "cc", just replace "cc" with "gcc" in the following commands. cc -c readdir.c cc -o client client.c cc -o server server.c readdir.o You don't need "-lsocket" on bayou or Linux. Also, don't forget to change HOST in the client.c, otherwise your client program can't talk to server. Also, when you run the client program, you should give a directory name (such as "/") as the parameter for client program, otherwise you will get "segmentation fault." 2. Do we implement the message packet as a string or a file? A: Usually, the message structure used by most of the protocols are implemented as a raw unsigned character array. So, you can implement message structure as a 42-byte unsigned character array. If you put a "\0" at the end of "Message" field, you can treat "Message" field as a string. But you should be aware that "Session ID" and "Code" fields are 2-byte unsigned integers. 3. Is the program graded for output or also how good the programming style is? A: Your programs will be graded for required functionalities, outputs, documents/comments, and correctness. Good programming style (format) will be a factor but will be considered as a part of documentation. 4. [from Mark] Did anyone notice that there was a mistake in state diagram for assignment #2? The arrow from 300 to 100 should be from 400 to 100. Sorry for the mistake that I made. Also, in the "readme" file, you should provide instructions of how to compile your programs, and how to run your programs (including explanation of command line parameters.) 5. Do we have to handle all kinds of error checking? A: You don't have to and this is not the purpose of this assignment. The possible errors that you should check are - incorrect Unique ID - incorrect Session ID - unknown commands (check the first word of messages, two words if "ASK"; and you can assume there is no funny/extra word/character in the message; if unknow code is received, you treat it as unknown command). - out-of-order commands You can assume "code" is always consistent with command in the message field and TA will not type over 34 bytes in the message. 6. In (2) you mentioned to put a "\0" at the end of message to make it a string. Could you elaborate on that? A: The message field (MSG) is basically a string (which contains the answer to client). So you can put "\0" at the end of MSG to identify the ending of message (which just like a string). Or you can use two consecutive blanks (" ") to indicate the end of message. Or you can find something similar. The idea is to make it simple, so you don't have to spend so much time to implement it. 7. How to convert integer to a 2-byte char array? A: Check out the binary operators on integer. Here is an example. unsigned int i, j; unsigned char c[2]; /* encoding */ c[1] = (char) (i mod 256); or c[1] = (char) i; c[0] = (char) (i div 256); or c[0] = (char) (i >> 8); /* decoding */ j = (int) c[0] * 256 + (int) c[1]; 8. I am using JAVA for this assignment. What should I do to have my programs graded? A: 1) You should send me an e-mail, so I will know who and how many students will use JAVA. 2) You have to turn in your programs like everyone else in the class, but do make a note in the README that you use JAVA and what kind of environment (compiler/OS) you use. 3) You should provide proper instructions to compile/run your programs, especially on which machine she can run your programs. If you need special software which is not available in the department or campus, you are responsible to setup a machine which have everything you need to compile and run your programs (you may use your own notebook/ PC). I would strongly suggest you to set up an appointment with TA and demo your programs. 9. Exactly which parameters are we allowed to hard code into the program and which ones do we need to get as inputs from the user? A: There are several parameters used in your programs. - server's host name: part of command line parameters; server should be able to get its host name by using system command "hostname" or gethostname() - client's host name: input by user from client program as part of message - port number: part of command line parameters - unique ID: hard coded in both client and server program, but should be able to be changed in debugging mode - session ID: generated by server and used by both client and server; when server receives a new "HELO" command, a new session ID is generated; should be able to be changed in debugging mode - user name: input by user from client program as part of message - code: input by user from client program; server can understand the code with corresponding commands in message field - message: input by user from client program; server will decode the message Also, both client and server should keep track some parameters used by both programs. - unique ID: both (hard coded) - current session ID: both - server's host name: server - client's host name: server - user name: server 10. We need print the message from client and server. That means we print client message in client program and print sever message in server program. It is right? A: You should print out messages from client and server on both client and server. You only need to write one function (well, maybe two) and use in both programs. Also, you can check if message received is the same as what you have sent. 11. As code number and session number, whether we need to change them into string and attach to message? A: How to include numbers (code and session ID) in the message seems confusing lots of students. Basically, the message sent and received is a 42-byte array (you can declare it as "unsigned char msg[42]"). Session ID is stored in msg[4] and msg[5] (where SID = 256 * msg[4] + msg[5]) and code is stored in msg[6] and msg[7] (where code = 256 * msg[6] + msg[7]). So when you construct message block, you copy unique ID, session ID, code, and message in to msg[] (to their corresponding positions). And then you send msg[] over to the other program. 12. Can I use sscanf() to read in the message field? A: No. There is a difference between sscanf() and gets(). sscanf() use white space (blank, tab, new-line) as separater. If you use sscanf() to read message field, say "HELO from Houston" with sscanf(msg, "%s"), you will only get "HELO". It would be saver to use gets(). But be aware that gets() might add a new line at the end of string (need to be confirmed). 13. Do I have to implement debugging mode for server program? A: No. Only client program needs debugging mode. 14. My programs run fine on bayou, but when server running on pegasus and client running on bayou, it wouldn't connect. A: There is a firewall in CS dept. and it will block unknown ports. If your programs run fine on the same machine, your programs should be OK. 15. I am still confuse how to send a message. Should I send "ABC1 23 300 ASK DATE" or just "300 ASK DATE"? A: Inside the message structure (say "unsigned char msg[42]"), msg[0~3] is unique ID, msg[4~5] is session ID, msg[6~7] is code, and msg[8~41] is message field. When you send a message structure to and from server, all these 4 info should be included. In non-debugging mode, you only type in code and message in the client program, but your program should fill in unique ID and session ID automatically (well, you program it to do so). In the debugging mode, user input all 4 info and put them into a message structure and then send to server, regardless what original unique ID and session ID are. 16. When I use gets() to input message from user, it just skips the input prompt and jump to the next time. So it wouldn't read in the message. What's wrong? A: If you have a scanf() before gets(), the gets() will read '\n' from buffer and jump to next line of code. So you can do something like this to remove '\n' from the buffer. char s[10], c; scanf("%s", s); c = getchar(); gets(s); 17. How do I get date & time for "ASK DATE" command? A: There is a ctime() which you can use. But you will need another function to get the current, since ctime() only print out the formated date/time. Here is an example using time(). time_t tm; time (&tm); printf("%s", ctime(&tm)); 18. My programs can be compiled on bayou. When I compiled them on pegasus, I got lots of errors. A: Use gcc on pegasus, instead of cc, and the problem will go away. 19. I can't submit my programs on bayou. A: You have to submit your programs on pegasus or other SunOS machines in the CS dept. 20. I still have problem submitting my programs on pegasus. A: Your programs and the directory where your programs locate should have read and read/execute (for dir) permission turned on. For example, your files are named a1.c and a2.c, and stored in ~myname/homework. Before you submit your programs, you should have (ls -la ~myname/homework) drwxr-xr-x 6 myname 512 Oct 12 13:39 . drwxr-xr-x 6 myname 512 Oct 14 13:39 .. -rw-r--r-- 1 myname 1234 Oct 10 15:37 a1.c -rw-r--r-- 1 myname 1543 Oct 10 15:47 a2.c And your home directory should have read/execute permission on also. (ls -la ~myname) drwxr-xr-x 6 myname 512 Oct 12 13:39 . drwxr-xr-x 6 myname 512 Oct 14 13:39 .. drwxr-xr-x 6 myname 512 Oct 14 13:39 homework ...... You can use "chmod" command to change access permission of files and directories. After finish submitting, remind you to turn off the read permission of your directories and files, so others cannot steal your works.