如何等待超时的返回消息 [英] how to wait for a return message with time out

查看:140
本文介绍了如何等待超时的返回消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我想编写一个简单的服务器 - 客户端应用程序,主要的目的是在连接建立后通过GUI运行某种类型的脚本,所以基本上是

我想建立连接



我现在拥有的是



 internal bool connect(remoteIP)
{
if(network.startping(RemoteIP))
{
peer1.write(Hello!)--->等待连接直到超时
if(Isconnected)返回true
}
else
{
几秒钟后再次尝试重复有限次数
}
返回false
}



1)我能做些什么等待我看到

任务的方法wait =  new  task.factory(()= >  doDwaiting())

我认为可以工作,但我在这里缺少一些逻辑2)我怎么能做回报我认为我可以用int Counter和goto做它但它看起来不像是好的方式去



我该怎么办?

解决方案

Socket.ReciveTimeout [ ^ ]可以帮助您实现是客观的。


Hello everyone
I want to write a simple server-client application , the main pursue is for it is to run a script of some type via GUI after connection established , so basically
I want to make connection conformation

what I have now is

internal bool connect(remoteIP)
{
 if ( network.startping(RemoteIP))
 {
  peer1.write("Hello!") ---> waits for "connected" until time out 
  if (Isconnected) return true
 }
 else 
  {
   try again after few sec with finite number of repeats
  }
 return false
}


1) what can I do to wait I saw a way with

Task wait = new task.factory(()=> doDwaiting())

with I think can work , but I I'm missing some logic here 2) how can I make the return i think I can Do it with int Counter and goto but it doesn't look like the "good" way to go

what can I do ?

解决方案

Socket.ReciveTimeout[^] could help you achieve this objective.


这篇关于如何等待超时的返回消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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