Winsock循环直到主机联机
Winsock looping until host comes online
我有一个客户端,它基本上想(不时)连接到远程主机,发送一些消息并断开连接。但主机可能并不总是可用的。我如何设置一个执行类似操作的循环(最好避免一些持续的cpu耗时循环):
尝试发送数据(数据数据)
主机在线吗否:再次检查是:连接,传输此数据,断开连接,返回
(我使用的是C++、WinSock2和TCP协议)
在一个完全无关的注释上,但由于你删除另一个问题时我正在处理它,我将把它发布在这里,并在你有时间看一看后立即删除。
对于其他读者来说,是的,这不是这个问题的主题,但也许我们需要某种消息传递系统
首先,重构getInterSection
:
# This return 2, 3 or 4 items, depending on the position
def getInterSection(x,y,grid):
intersections = []
if y > 0:
intersections.append((x, y - 1))
if y < grid[1] - 1:
intersections.append((x, y + 1))
if x > 0:
intersections.append((x - 1, y))
if x < grid[0] - 1:
intersections.append((x + 1, y))
return intersections
像这样使用:
intersect = getInterSection(x,y,grid)
# This is a uniform choice, therefore probability is as expected 1/2, 1/3 or 1/4
x,y=random.choice(intersect)
相关文章:
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 如何停止 CLR 主机?
- 如何强制 Thrift 仅接受来自本地主机的连接
- 库达如何将字符**从内核复制到主机
- Poco::Net::FTPClientSession 在 open() 方法上挂起 129 秒,如果 ftp 主机不存
- 如何在 2 台主机之间保持 UDP 套接字连接打开
- 如何在 cuda 中将 kd 树从主机复制到驱动程序
- 代码未在联机编译器上显示结果
- 为什么联机C++ IDE 不支持"graphics.h"头文件?
- Poco 库 PUT 方法未按预期工作,尽管主机、方法、内容类型设置正确
- OpenCL 错误类在主机C++给出错误
- 来自复杂主机数据的阵列火力阵列
- 分离库的主机端和 CUDA 设备端版本
- 如何将HTTPS流量重定向到本地主机:443上的代理?
- Cesanta Mongoose - 连接到本地主机时出现问题
- C++ / Qt:如何检测主机名或IP地址何时引用当前系统?
- 如何实现从 Windows 脚本主机到脚本的事件调度
- 下载 GPU Mats 的矢量到主机
- Winsock循环直到主机联机