Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This member function is looped until program termination */
- void pdmudServer::ConnectionMonitor()
- {
- int nbytes, result;
- /* rd, wr, and ex are private members of type fd_set in pdmudServer */
- /* MAX_PLAYERS is a const int in the pdmud namespace; set to 20 for now */
- /* player is a member of class pdmudServer of type vector<pdPlayer> */
- result = select(MAX_PLAYERS, &rd, &wr, &ex, NULL);
- if (result < 0)
- throw(pdmudServerError());
- if (FD_ISSET(server_fd, &rd)) /* Check for activity on server socket */
- {
- std::cout << "Player connecting.\n";
- pdPlayer newplayer;
- player.push_back(newplayer);
- (player.back()).ConnectPlayer(server_fd, &rd, &wr, &ex); /* Player accept */
- }
- for (int i = 0; i < player.size(); i++)
- {
- int fd = (player.at(i)).GetFD();
- if (FD_ISSET(fd, &rd)) /* Check for this player activity */
- {
- char buf[256] =
- { "\0" };
- nbytes = recv(fd, buf, sizeof(char) * 256, 0);
- if (!nbytes)
- {
- /* No data read; player must be disconnecting */
- close(fd);
- FD_CLR(fd, &rd);
- std::cout << "Player disconnecting.\n";
- }
- else
- {
- /* data read from player; print it */
- buf[nbytes] = '\0';
- std::cout << "Player input: " << buf << "\n";
- }
- }
- } /* End for */
- } /* End ConnectionMonitor */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement