13.07.2015 Views

Beej's Guide to Network Programming Using Internet Sockets

Beej's Guide to Network Programming Using Internet Sockets

Beej's Guide to Network Programming Using Internet Sockets

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Beej’s <strong>Guide</strong> <strong>to</strong> <strong>Network</strong> <strong>Programming</strong> <strong>Using</strong> <strong>Internet</strong> <strong>Sockets</strong> 31}}if (select(fdmax+1, &read_fds, NULL, NULL, NULL) == -1) {perror("select");exit(1);}// run through the existing connections looking for data <strong>to</strong> readfor(i = 0; i fdmax) { // keep track of the maximum}}return 0;fdmax = newfd;}printf("selectserver: new connection from %s on ""socket %d\n", inet_n<strong>to</strong>a(remoteaddr.sin_addr), newfd);}} else {// handle data from a clientif ((nbytes = recv(i, buf, sizeof(buf), 0))

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!