2

I have a C program running on Linux that will receive data from 4 different IP addresses, on the same UDP port every 250mS (4 times a second). The data coming in on each socket is no more than 120 bytes per socket, and uses UDP. My question is, if I use the select() Linux call, would I be able to process all the data without missing any if the data arrives on the sockets at the same time? Would I have to use Pthreads instead?

If I do use select() would I just have to dump the data into buffers every 250mS then process it after I receive all four sockets data from select()? Assuming the processing can be completed within 250mS which it should only take 10mS or less.

melpomene
  • 84,125
  • 8
  • 85
  • 148
user8351154
  • 89
  • 1
  • 4
  • 2
    The OS Buffers data for you. Do not worry about the timings. Besides the OS might be running other stuff as well that takes more that the 1/4 second to get around to you – Ed Heal Jul 22 '17 at 20:45
  • `select()` will get the job done, but you may want to use `poll()` or `epoll()` instead if available on your system. See https://www.ulduzsoft.com/2014/01/select-poll-epoll-practical-difference-for-system-architects/ – augurar Jul 22 '17 at 20:47
  • Do you think since all data coming in will be on the same UDP port, I could use only 1 socket, or should I keep it to 1 socket per "client"? – user8351154 Jul 22 '17 at 21:03
  • 2
    @user8351154 In that case you only need one socket and you don't need to use `select` at all. See also: https://stackoverflow.com/questions/6148174/can-mutiple-sockets-be-associated-with-same-port-for-udp – augurar Jul 22 '17 at 21:05

0 Answers0