65/* Establish the TCP connection. Accept() returns a new
66socket number for the connection, allowing listen() to
67(if desired) continue to listen on the old socket.
68
69Parameters to accept() are: the socket that the
70previous listen() call was using, a sockaddr structure,
71and the length of the sockaddr structure. The second
72and third parameters are zero here, but can be used to
73get the IP address and port number of the remote end of
74the connection. */
75msgsock= accept(sock, (struct sockaddr *)0, (int *)0);
76if
77perror(“accept”);
78}
79else do {
80memset(buf, 0, sizeof(buf));
81if ((rval= read(msgsock, buf, 1024)) < 0)
82{
83 | perror(“reading stream message”); |
84 | exit(5); |
85}
86else if (rval==0) {
87 | printf(“Read zero bytes. Exiting...\n”); |
88exit(6);
89}
90else {
91 | /* Print out data on screen and log it to the logfile. |
92 | Note we are skipping the Serial Adapter header bytes. */ |
93 | printf(“Read %d bytes\n”, rval); |
94 | buf[rval]= ‘\0’; |
95 | if (rval > 4) |
96 | printf(“Data: |
97 | for (i= 0; i< rval; i++) |
98 | fputc(*(buf+i), logfile); |
99 | fclose(logfile); |
100 | logfile= fopen(“proxlink.log”, “ab”); |
101}
102} while (TRUE);
104} while (TRUE);
105}
93