大家好,正常收取数据部分已经实现,关于重连我是如下的操作,但是有问题,还请大家指教
链接方式通过线程方式链接
链接按钮脚本如下
Dim threadConnect_2 As New Thread(New ThreadStart(AddressOf startConnect_2))
threadConnect_2.Start()
startConnect_2函数如下
address_2 = IPAddress.Parse(txtAddress2.Text.Trim)
port_2 = Integer.Parse(txtPort2.Text.Trim())
connect_2 = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim asyncCallBack_2 As New AsyncCallback(AddressOf connectEnd_2)
connect_2.BeginConnect(New IPEndPoint(address_2, port_2), asyncCallBack_2, connect_2)
重连方法如下
intByte_2 = connect_2.EndReceive(pIAsyncResult)
If connect_2.Available = 0 And intByte_2 = 0 Then
connect_2.Close()
txtMessage.AppendText("Client_2:" + " 您已断开连接!")
Dim threadConnect_2 As New Thread(New ThreadStart(AddressOf startConnect_2))
threadConnect_2.Start()
End If