winsock两个问题,关闭后怎么重新监听?在close事件中不能重新listen?

Private Sub Command1_Click()
sock.Close
End Sub

Private Sub Command2_Click() 'tcp测试
sock.Connect "192.168.200.10", 39963
Debug.Print sock.State
End Sub

'--------------------------------------以上是客户端

'-------------------以下服务器端

Private Sub Command1_Click()
wsk.Close
Debug.Print "sock关闭后:" & wsk.State
wsk.LocalPort = 39963
wsk.Listen
Debug.Print "当前sock:" & wsk.State
End Sub

Private Sub Form_Load()
wsk.LocalPort = 39963
wsk.Listen
edeal:
If Err.Number = 10048 Then
If wsk.State = 1 Then wsk.Close
wsk.LocalPort = 64399
wsk.Listen
End If
Debug.Print "newLocalIP:" & wsk.LocalIP & " " & wsk.LocalPort
End Sub

Private Sub Form_Unload(Cancel As Integer)
End
End Sub

Private Sub Timer1_Timer()
On Error GoTo Errs
wsk.SendData "xtbjc"

Errs:

If Err.Number <> 0 Then
Timer1.Interval = 0
wsk.Close
End If
End Sub

Private Sub wsk_Close()
Debug.Print "产生关闭事件了"
Timer1.Enabled = False
Text1.Text = "客户端断开了!"

'wsk.Listen '在这里不能启动监听?????**********************
End Sub

Private Sub wsk_ConnectionRequest(ByVal requestID As Long)
Debug.Print "产生连接事件了"
If wsk.State <> 0 Then wsk.Close
wsk.Accept requestID
Timer1.Interval = 2000
Text1.Text = "连接成功"
End Sub

查看全部
ecz00
ecz00
2015/07/24 20:52
  • winsock
  • vb6
  • 点赞
  • 收藏
  • 回答
    私信

1个回复