请说明如何制作事件级套接字程序 [英] Please tell how to make event level socket program

查看:78
本文介绍了请说明如何制作事件级套接字程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个套接字程序,该程序可以连接到服务器并发送消息,但我无法执行的操作是:-
创建一个事件,如果在我通过该套接字连接到套接字的套接字上写了一些东西,并且必须在该事件上调用recv()时,将设置该事件.
如果我没有收到服务器的任何响应,则应在5秒钟后再次拨打send呼叫.
怎么做.
请建议

I was trying to make a socket program,in which i was able to connect to server and send message but the part that i would was not able to do is:-
Make an event which will be set if something is written on the socket through which i have connected to the socket and when the event i have to make the recv() call.
And if i didn''t get any response from the server i should make the send call again after 5 second.
How can it be done.
Please suggest

推荐答案

您真正需要的第一件事是 [
The first thing you really need is this[^]

Then you can go on to read this[^] that might be able to help you.


在单独的线程上使用select()等待数据(您也可以设置超时值).
然后调用recv()读取数据.如果发生超时,请(重新)将数据发送到您的服务器.
Use select() on a separate thread to wait for data (you can also set a timeout value).
Then call recv() to read the data. If timeout occurs, (re)send data to your server.


这篇关于请说明如何制作事件级套接字程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆