Path: utzoo!attcan!uunet!bloom-beacon!bu-cs!madd From: madd@bu-cs.BU.EDU (Jim Frost) Newsgroups: comp.unix.wizards Subject: Re: socket communication problems Message-ID: <38713@bu-cs.BU.EDU> Date: 22 Sep 89 20:05:18 GMT References: <16453@watdragon.waterloo.edu> Reply-To: madd@std.com Followup-To: comp.unix.wizards Distribution: na Organization: Boston University Distributed Systems Group Lines: 26 In article <16453@watdragon.waterloo.edu> sekoppenhoef@rose.waterloo.edu writes: |Shouldn't I be able to read and write on |BOTH ends of a socket connection? [...] |What am i doing wrong? [...] |**These two commands are what I'm using to write and read... the 'write' works |**on the client end but not the read, and vice versa for the server end |the server end uses an ACCEPT to get the scket name for communication of course. | write(sock, buf, n) | read(sock,buf,sizeof(buf) ) This will fix your problem: for (i= 0; i < sizeof(buf);) i += read(sock, buf + i, sizeof(buf) - i); How fondly I remember having this same problem, asking Barry Shein about it, and hearing "did you check the return value from read?" and feeling very silly. You'll find that socket reads don't read the whole thing much of the time. Note that you should really do error checking in that loop, too. jim frost software tool & die madd@std.com