Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!dali!milton!eliot From: eliot@milton.acs.washington.edu (Eliot Lim) Newsgroups: comp.unix.wizards Subject: Socket problem, please help Message-ID: <2812@milton.acs.washington.edu> Date: 11 Apr 90 18:50:02 GMT Reply-To: eliot@dodongo.engr.washington.edu (Eliot Lim) Organization: University of Washington, Seattle Lines: 63 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