如何使客户端服务器套接字程序异步?

时间:2019-04-11 14:20:06

标签: c sockets

我为客户端和服务器提供了以下代码。

它使用套接字编程进行linux中的通信。

客户

...
//after connecting to the server
while(1){
recv();//recv from the serv
//get user input using scanf()
send();
}
...

服务器

...
//Create a thread to handle each client request
//Inside client thread
while(1){
send()
...
recv()
}
...

这里,客户端仅在向服务器发送内容后才从中获取消息。 但是,即使没有将任何内容发送到服务器,我也需要接收消息。 我是否需要通过客户端中的多线程处理此问题?还是其他方式?

0 个答案:

没有答案
相关问题