socket connection dropping characters
Mike Putnam
putnam at peanuts.nosc.mil
Fri Apr 13 06:59:33 AEST 1990
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 at nosc.mil
UUCP: sdcsvax!noscvax!putnam
More information about the Comp.unix.questions
mailing list