简体   繁体   English

WinSock客户端C

[英]WinSock Client C

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(). 我有一个使用select()的客户端来检查是否有任何要接收的内容,否则它超时并且用户能够发送()。 Which works well enough. 哪个效果很好。 However, the program locks up waiting for user input, so it cant recv() again until the user has sent something. 但是,该程序锁定等待用户输入,因此它无法再次recv(),直到用户发送了一些东西。 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. 我尝试过为发送和接收函数创建两个线程(使用CreateThread),这基本上是两个使用while循环保持发送和接收函数的函数。 And then the two CreateThreads() are wrapped up in a while loop, because otherwise it just seemed to drop out. 然后,将这两个CreateThreads()封装在while循环中,因为否则它似乎就退出了。

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. 但是,如果能适当地将它们用于此类使用,我将不胜感激,否则替代方法也将非常有用。

Can't find a good resource on socket programming? 在套接字编程方面找不到好的资源? Bah. 呸。 Read the bible: 阅读圣经:

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. 我不太喜欢Windows编程,但是当我做得较早时,曾经有一个kbhit (可能)函数,该函数可让您检查用户是否发送了任何输入。 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). (除非,嗯,您必须使用它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM