如何知道Tcp连接是否结束我怎么知道

如何知道Tcp连接是否结束我怎么知道

本文介绍了如何知道Tcp连接是否结束我怎么知道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,谢谢你试图帮助我

我正在廉价制作一个DVD农场,我正试图在VB.Net中为自己编写代码

i制作了一台可以在每台计算机上运行的软件和一台为主计算机发送命令的软件。



现在,我一直想要机器听主电脑连接,所以我写了这段代码:

变量:

Hi everyone, thank you for trying to help me
I'm making a DVD Farm on the cheap and i'm trying to write the code for myself in VB.Net
i have made a software that runs on every computer and a software for the main computer that sends commands to all of them.

Now, i always want the machines to listen to the main computer for connection, so i wrote this code:
Variables:

Dim server As New TcpListener(45888)
        Dim client As New TcpClient
        Dim stream As NetworkStream





首先,我等待连接:



First, i wait for connection:

server.Start()
        client = server.AcceptTcpClient
        stream = client.GetStream





然后,通过使用线程,我开始听cicle:



Then, with the use of a thread, i start the listening cicle:

While client.Connected
If client.Available > 0 Then
''read commands
''do stuff
End if
End While





这是问题所在:

当我使用此代码连接到机器时,一旦我断开连接,机器仍然认为它已连接,使得第二次无法连接到它,client.Cinnected似乎没有工作正常,我希望机器检测连接何时结束以重启过程。



这应该有效吗?我做错了什么?



Here's the problem:
When i connect to the machine with this code on it, once i disconnect, the machine still thinks it's connected, making it impossible to connect to it a second time, the "client.Cinnected" doesn't seem to work properly, i would like the machine to detect when the connection is over to restart the process.

Is this supposed to work? am i doing something wrong?

推荐答案


这篇关于如何知道Tcp连接是否结束我怎么知道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 12:21