0
votes

I would like to make two way communication using TCP and UDP socket in linux. The idea is like the following. This is a kind of sensor network.

server side

while loop (

(1)check if there is incoming TCP control message if yes, update the system based on control message

for all other time, keep spamming out UDP messages

)

client side

while (

keep receiving the UDP broadcast message

once it receives 100 UDP messages, it has to send a TCP control message to server

)

The (1) part is the only place that I cannot work out. I find that if I use non blocking TCP socket with select() on the (1) part for short interval, the system will soon return 0 and the control message is not received. Either I would set a long interval for select, but it will block the line and the UDP message cannot send it out. I want the UDP message sending out effectively , provided that the server can also notice the client TCP control message at any tinme.

Could anyone give me some hints on (1) part.

1

1 Answers

0
votes

You should only attempt a recv() if the correspond readFD is set after select(). If select() returns zero, none of them is set: the timeout has expired, so you shouldn't do so anything except send your UDP message.