我有一个异步Socket程序,有时候客户端能够连接上服务器,但是有时候却积极拒绝,这是怎么会事啊?这是我程序的代码: Private Sub StartListen()
Dim intport As Integer
Dim bidEndPoint As IPEndPoint
intport = Integer.Parse(TextBox1.Text)
Dim myip As IPAddress = IPAddress.Parse("192.168.162.180")
bidEndPoint = New IPEndPoint(myip, intport)
mylistener = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Try
mylistener.Bind(bidEndPoint)
Dim myAsyncCallBack As New AsyncCallback(AddressOf AcceptEnd)
While True
mylistener.Listen(intport) '参数为挂起队列的长度
mylistener.BeginAccept(myAsyncCallBack, mylistener)
TextBox2.Text += vbCrLf + "等待连机中,开始整理数据......"
'有一段代码没有写呢?哈哈(无关紧要的代码)
End While
Catch ex As Exception
MessageBox.Show(ex.Message, "打开连接错误", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
End Sub
Private Sub AcceptEnd(ByVal pIAsyncResult As IAsyncResult)
EndSocket = mylistener.EndAccept(pIAsyncResult)
Button3.Enabled = True '将接受按钮置于能够用的状态
TextBox2.Text += vbCrLf + "已接受客户端的请求!!"
End Sub
(服务器端的)