开发者

C: Sockets without stop and wait

I'm creating a tftp-like program but instead of stop and wait, I'm trying to use a go-back-n approach. I'm not exactly sure how to go about this as I have very little socket programming experience.

I have my client sending all of the data with sendto, and am currently just not calling recvfrom because it will wait until I get a response, but I don't want it to wait. I want to check if there was a response, but if not, keep sending data.

Can someo开发者_Go百科ne point me in the right direction? Please let me know if more information is needed, I'm having trouble elaborating.

Thanks!


Create a non-blocking socket and use select() (or poll() or whatever other mechanism you have at hand) to wait for both writability and readability of the socket. Then respond appropriately to each state independently when it arises.

I've never done this with UDP, but I see no reason that it shouldn't (a quick Google seems to reaffirm that).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜