开发者

UDP using socket API

开发者 https://www.devze.com 2022-12-16 22:07 出处:网络
My server use UDP. It sends 900bytes/1ms to my program automatically after being acquired. I\'m using socket API in Windows (VB6). I had made a test and I know that the message processing time (about

My server use UDP. It sends 900bytes/1ms to my program automatically after being acquired. I'm using socket API in Windows (VB6). I had made a test and I know that the message processing time (about 0.3ms) of my program is shorter than cycle time (1ms). So the cause should be socket internal buffer. I try calling setsockopt function to set the bigger buffer:

开发者_如何学JAVAsetsockopt(SockNum, SOL_SOCKET, SO_RCVBUF, SockBuffer(1), 1048576)

but I still lost data. How can I fix my problem? I'm using recv function to receive data. Should recvfrom be better?

Futhermore, I need make a FIFO buffer for UDP. How I can do so (i.e. algorithms or examples)?


In your question you seem to be complaining about using UDP and losing data.

If you are using UDP, you are going to lose data. The way that you avoid losing data is to use TCP, not UDP. If you try to take the User Datagram Protocol and add reliable delivery of data to it, you will end up with something that has all of the flow-control and data windowing of TCP... except it won't be implemented as well as you want.

Remember, "Those who do not understand TCP are doomed to reinvent it.... poorly"

0

精彩评论

暂无评论...
验证码 换一张
取 消