How can I use poll to accept multiple clients? (TCP Server) (C)
Asked Answered
S

1

8

This polling business seems like it was written by a madman, and I am unsure how to use it to allow for multiple clients to connect to a server and then send their input to all other clients.

So if I want to have three clients going, I will need something like:

  ufds[0].fd = sd;
  ufds[0].events = POLLIN;
  ufds[1].fd = sd2;
  ufds[1].events = POLLOUT;
  ufds[2].fd = sd2;
  ufds[2].events = POLLOUT;
  ufds[3].fd = sd2;
  ufds[3].events = POLLOUT;
  ufds[4].fd = sd2;
  ufds[4].events = POLLOUT;

And then do what exactly so that messeges can be read in and written out?

Shedd answered 15/12, 2014 at 22:52 Comment(0)
E
4

Here is an example using "C" and "select" on Linux:

http://www.binarytides.com/multiple-socket-connections-fdset-select-linux/

Here is an example using "poll":

http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzab6/poll.htm

Evoke answered 15/12, 2014 at 22:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.