C:没有停止和等待的套接字
我正在创建一个类似 tftp 的程序,但我没有停下来等待,而是尝试使用 go-back-n 方法。我不太确定如何解决这个问题,因为我几乎没有套接字编程经验。
我让我的客户端使用 sendto 发送所有数据,目前我只是不调用 recvfrom,因为它会等到我收到响应,但我不希望它等待。我想检查是否有响应,如果没有,则继续发送数据。
有人能指出我正确的方向吗?如果需要更多信息,请告诉我,我无法详细说明。
谢谢!
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 someone point me in the right direction? Please let me know if more information is needed, I'm having trouble elaborating.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个非阻塞套接字并使用
select()
(或poll()
或您手头的任何其他机制)来等待套接字的可写性和可读性。然后,当每种状态出现时,独立地对其做出适当的反应。我从未使用 UDP 这样做过,但我认为没有理由不这样做(快速谷歌似乎重申了这一点)。
Create a non-blocking socket and use
select()
(orpoll()
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).