/* server for inet stream demo */ /* cmd format: istr */ #include #include #include #include #include #define TRUE 1 #define MAXLINE 256 /* this program creates a socket and then begin an infinite loop. Each time * through the loop, it accepts a connection, prints out messages from it, * and then ask for reply message from the user. * When the connection breaks, or a termination messgage come through, the * program accepts a new connection. */ getline(s, lim) char s[]; int lim; { int c, i; for (i=0; i%s\n", buf); printf("What is your reply (\"$\" to break connection)?"); if ((rval=getline(fromBuf, 1024)) <= 0) break; if (fromBuf[0] == '$') { rval = 0; break; } /* send back reply */ if (write(msgsock, fromBuf, strlen(fromBuf)) < 0) perror("writing on stream socket"); } while (rval != 0); close(msgsock); } while (TRUE); }