0
votes

I'm writing two programs(on visual studio), one sending and one receiving UDP packets(1,000 bytes). Currently, my sender is sending a udp packet, sleep for 1 ms, before sending another packet. To increase the rate, i made the sender sleep for 1 ms only after sending about 20packets. Problem is if i increase the number of packets before each sleep, the receiver tend to miss packets. So i thought maybe if i increase the socket buffer size it will be better?

I know TCP is a safer choice, but let's assume i can only use UDP, and i need to ensure i can send packets over at a high rate with no missing packets, what should i do? And how do i check what is my socket buffer size? Currently my program only used 'sethost' and 'bind', followed by 'sendto' to send udp packets.

1
TCP is a reliable, connection-oriented stream protocol. UDP is a unreliable, connection-less datagram protocol. For 99% of applications there is only one right choice. You haven't told us anything about your application, but it certainly doesn't make sense to try and make your receiver handle thousands of packets of information instantaneously. If it is time-based data you are sending, then send it at a fixed rate. There just isn't enough information here to answer the question.Jonathon Reinhart
"i need to ensure i can send packets over at a high rate with no missing packets" the best you can do is increase your buffer size with setsockopt() / SO_RCVBUF, then have the receiving side dedicate a thread to reading incoming network data into the application's queue as quickly as possible, so other data processing doesn't block/slow the receipt leading to packet loss. Increase the scheduler priority if necessary. Then pray. This approach is only really ok if you can afford to lose data.Tony Delroy

1 Answers

1
votes

You can set the socket buffer size with setsockopt() using the SO_RCVBUFSIZ or SO_SNDBUFSIZ options, and you can get it back via getsockopt().

However I agree with @JonathonReinhart that this is most unlikely to fix your real problem.