UDP protocol in a conditional statement?

I'm facing a serious problem with udp protocol. I have Master & Slave devices.I did implement the class as the follow pseudo code states

In Master side
1
2
3
4
5
6
while (true)
{
1-send data to slave;
2-get data from slave;
3-apply force;
}


In Slave side
1
2
3
4
5
6
while(true)
{
1-get data from master;
2-if (collision happnes)
send force to the master
}


the problem is in line 2 in Master side. Once I include the line I can't send or receive data. What do you think the problem is?
Last edited on
If the slave doesn't have a collision there is nothing for the master to read. The master would then be blocked forever, unless you have a timeout on the master read.

As a test make the if check for collision in the slave always true and see if your program works. This way the slave is always sending data to the master and when it posts a read there will be something there for it to read.
@histrungalot, thanks for the answer.
The problem was in winsock. For recvfrom(), the default mode is blocking mode. I've changed it to non-blocking mode and it worked; however, I've got another problem which is recvfrom() and sendto() slow down the process a little bit. I don't why? I've tried send() and recv() but with no luck.
1. What do you mean by "slow down the process"?
2. And how do you know it is slow?
3. Compared to what?
4. When did it run fast?
Topic archived. No new replies allowed.