CSS 432
FAQ on Program 1: Basic TCP Communication
Q1: Should we use C or C++?
A: Use C++.
Q2: May I use the code in the lecture slides from CSS432 and/or
CSS434?
A: Yes, you can
Q3: Where is gnuplot?
A:/usr/bin/gnuplot
If you want to know how to use it, type "man gnuplot". Also, visit http://www.gnuplot.info
Q4: Should I use the "flush" system call?
A: No.
For data transfer, you should just use write and read system calls.
Q5: What header files should I inclulde for each system call?
A: Use man.
If you would like to know the usage and the header files required
for the "write" system call, type
man 2 write
where 2 means the section 2. In general, most system calls are
described the section 2. The "man" page displays:
SYNOPSIS
#include
ssize_t write(int fd, const void *buf, size_t count);
...
So, what you need is to include the "unistd.h" file.
Q6. How can a server know the size of message it receives from the
client?
A. You may hard-code the server in that you make sure to increment
the message size in the same way in the server as we do in the
client
Q7. I got a "Broken pipe" error.
A. Your client and server program didn't agree at the number of
messages exchange and the message size, and thus one of them exited
earlier than the other.
The client and server must agree how many bytes to send and read.
If the client sends 100, 200, 300, and 400 bytes, the server must read
100, 200, 300, and 400 bytes. Since server sends back a 1-byte acknowledgment
for every message, the client must read 1 byte after every message transfer.
If either cleint or server exits and its counter part still tries to send
a message, the socket (=pipe) has been already gone and you'll get a
broekn error.
Q8. When I tried to compile the following program, I got a bunch of errors.
int main( void ) {
write( 5, "Hi there!", 9 );
return 0;
}
A. Include header files necessary to execute the "write" system call and
open a file descriptor first.
Check the answer for Q5. Thereafter, you have to receive a file descriptor
explicitly from OS with open. In the above code, you are using the file
descriptor 5 without receiving this descriptor from OS. First open a file
or a socket.
Note that you can use the file descriptors 0, 1, and 2 without calling
open( ). They are automatically opened and correspond to stdin,
stdout, and stderr respectively.
Q9. The compiler complains about my usage of accept.
int len;
newSd = accept(sd, (strcute sockaddr *)&client, &len);
A. Use "socklen_t*" instead of "int*"
socklen_t len;
newSd = accept(sd, (strcute sockaddr *)&client, &len);
Q10. Do you want us to actually fill the message exchange between
a client and a server?
A. You don't have to fill it out.