C:没有停止和等待的套接字

发布于 2024-10-24 05:28:51 字数 236 浏览 4 评论 0原文

我正在创建一个类似 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2024-10-31 05:28:51

创建一个非阻塞套接字并使用 select() (或 poll() 或您手头的任何其他机制)来等待套接字的可写性和可读性。然后,当每种状态出现时,独立地对其做出适当的反应。

我从未使用 UDP 这样做过,但我认为没有理由不这样做(快速谷歌似乎重申了这一点)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文