WinSock客户端C

发布于 2024-08-11 05:45:12 字数 355 浏览 5 评论 0原文

我有一个客户端使用 select() 来检查是否有任何内容要接收,否则会超时并且用户可以发送()。效果很好。但是,程序会锁定等待用户输入,因此在用户发送内容之前它无法再次使用 receive() 。 我在使用线程方面也没有太多运气,因为我似乎找不到好的资源,这向我展示了如何使用它们。

我尝试为发送和接收函数创建两个线程(使用 CreateThread),这基本上是两个使用 while 循环来保持发送和接收的函数。然后两个 CreateThreads() 被包裹在一个 while 循环中,否则它看起来就会退出。

我以前基本上没有线程方面的经验,所以我对我所做的事情的描述可能听起来很荒谬。但我将不胜感激任何帮助,正确使用它们进行这种用途,或者替代方法也很棒。

I have a client using select() to check if there is anything to be received, else it times out and the user is able to send(). Which works well enough. However, the program locks up waiting for user input, so it cant recv() again until the user has sent something.
I am not having much luck with using threads either, as I cannot seem to find a good resource, which shows me how to use them.

I have tried a creating two threads (using CreateThread) for send and recv functions which are basically two functions using while loops to keep sending and receiving. And then the two CreateThreads() are wrapped up in a while loop, because otherwise it just seemed to drop out.

I have basically no previous experience with threads, so my description of what i've been doing will probably sound ridiculous. But I would appreciate any help, in using them properly for this kind of use, or an alternative method would also be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

来世叙缘 2024-08-18 05:45:12

找不到有关套接字编程的好资源?呸。阅读圣经:

Can't find a good resource on socket programming? Bah. Read the bible:

阳光下慵懒的猫 2024-08-18 05:45:12

这有很强的作业感觉...

我不太喜欢 Windows 编程,但是当我之前做一些事情时,曾经有一个 kbhit (可能)函数允许您检查用户是否发送了任何输入。您可以寻找类似的东西,并在再次开始选择之前尝试非阻塞用户输入检查。

然后你就可以在没有多线程的情况下让它工作
(除非,呃,你必须使用它)。

this has a strong feel of assignment work...

I am not too much into Windows programming but when I did do some earlier, there used to be a kbhit (probably) function that allowed you to check if the user had sent any inputs. You could look for something similar and try a non-blocking user input check before starting your select again.

You could then get this working without multi-threading
(unless, er, you have to use that).

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