Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!tut.cis.ohio-state.edu!ucbvax!pasteur!helios.ee.lbl.gov!nosc!peanuts.nosc.mil!putnam From: putnam@peanuts.nosc.mil (Mike Putnam) Newsgroups: comp.unix.questions Subject: socket connection dropping characters Message-ID: <2125@nosc.NOSC.MIL> Date: 12 Apr 90 20:59:33 GMT Sender: nobody@nosc.NOSC.MIL Reply-To: putnam@peanuts.nosc.mil (Mike Putnam) Distribution: usa Organization: Naval Ocean Systems Center, San Diego Lines: 58 X-Local-Date: 12 Apr 90 13:59:33 PDT Being new to the world of interprocess communications I wrote two simple test programs on an Apollo workstation running Apollo's version of BSD4.3. The first program, the server, opens a stream socket and waits for a connection. The second program, the client, connects to the server and goes into an infinite loop sending a string using the write command. The server reads the message and prints it to standard output. Unfortunately after about twenty or so writes by the client the server begins to drop characters. Below is the program fragments that do the actual reading and writing after the connection has been made: Server ********************************* do { FD_ZERO(&ready); FD_SET(sock,&ready); to.tv_sec = 5; if (select (sock + 1, &ready,0, 0, &to) < 0) { perror ("select"); continue; } if (FD_ISSET(sock, &ready)) { msgsock = accept(sock, (struct sockaddr *)0, (int *)0); if (msgsock == -1) perror("accept"); else do { bzero(buf, sizeof(buf)); if ((rval = read(msgsock, buf, sizeof(buf))) <0) perror("reading stream message"); else if (rval == 0) printf("ending connection\n"); else printf ("-->%s\n",buf); /* write(msgsock,OK,sizeof(OK));*/ } while (rval > 0); close(msgsock); } else printf("do something else\n"); } while (TRUE); Client ********************************* do { if (write(sock, DATA, sizeof(DATA)) < 0) { perror("writing on stream socket"); close (sock); } } while (TRUE); I assume the server is not reading as fast as the client is writing. Is there a simple way avoid the loss of characters passing through the connection? Mike Putnam Naval Ocean Systems Center San Diego, CA Internet: putnam@nosc.mil UUCP: sdcsvax!noscvax!putnam