Socket problem, please help

Eliot Lim eliot at milton.acs.washington.edu
Thu Apr 12 04:50:02 AEST 1990


Can anyone tell me why the following piece of code fails?  I've been
banging my head on the wall for days and I've had 2 other people look
at the code for obvious bugs.  I will only list pseudo code as I'd
like to know if there's anything fundamentally wrong with my approach.

The program is a file server/client using sockets for transfer.
The client program prompts the user for a filename, sends it through
the socket to the server, the server reads the file and sends it back
through the socket.

The client program behaves like this:

1) First iteration produces 100% expected results
2) Second iteration produces an empty output file
3) Third iteration the program exits, even though there are no 
   exits in the code.  (i.e. the code is a pure infinite loop;
   the error() routine was set up to print a msg and return.
4) No error messages are ever printed by the client or the server.

Assume that the socket is already connected.

client:

while(1){
	prompt(input);
	send(socket,input);
	creat(outfile);
	while(1){
		if ((result = recv(socket)) < 0) error;
		if result == 0 break;
		if ((result = write(outfile) < 0) error;
	}
	close(outfile)
}


server:

while(1){
	waitfor(input);
	open(input);
	while(1){
		if ((result == read(input) < 0)) error;
		if result == 0 {
			fflush(socket);
			break;
		}
		if ((result == send(socket) < 0)) error;
	}
	close(input);
}


The client/server code has been ported to different machines and flavors
of unix and it produces identical, consistent results every time, so 
I'm ruling out an OS bug.  Specifying identical or different input/output
files do not make any difference.  I have also tried different buffer
sizes with no results.

Any help or advice would be appreciated.


Eliot 



More information about the Comp.unix.wizards mailing list