TCPClient状态无变化 [英] TCPClient status no change

查看:80
本文介绍了TCPClient状态无变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用TCPClient打开连接,它能够读取和写入数据或字符串,但是当我关闭远程设备或拔掉网络电缆时,请检查client.connected属性,它总是显示 ;真" ;.会发生什么事?谢谢

I was able to open a connection using TCPClient, it is able to read and write data or string, however when I turn off the remote device or unplug the network cable, then check the client.connected property, it always shows "True". what could be happened? Thanks

推荐答案

连接属性只反映了最后一次读取或写入操作,我以前认为它使它变得无用。在属性发生变化之前,您必须尝试在已关闭的套接字上进行读/写。


幸运的是,我编写了以下函数,我觉得它运行得相当好。
The connection property is only reflective of the "last read or write operation", which I presonally feel makes it rather useless. You have to try to read/write on a closed socket before it the property changes.

Fortunatly I wrote the following function that I think works rather well.
展开 | 选择 | Wrap | 行号


谢谢,

但我正在使用VB2005,是否有与s类似的功能VB中的.poll()?顺便说一下民意调查功能在做什么?


谢谢
Thank you,

But I''m using VB2005, is there a similar function as s.poll( ) in VB? by the way what is the poll function doing?

Thanks


所有这些都在.NET中可用。因此无论是VB.NET还是C#,您仍然可以使用这些调用。你可以查看msdn上的Poll()函数
(只需要改成VB.NET语法)


编辑:快速在线转换产生这个,应该非常接近。
All of that is available in .NET. So whether its VB.NET or C#, you can still use the calls. You can check the Poll() function on msdn
(Just need to change to VB.NET syntax)

Quick online convert produced this, should be pretty close.
展开 | 选择 < span class =codeDivider> | Wrap | 行号


这篇关于TCPClient状态无变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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