控件名 | 控件类型 | 属性 |
Label1 | Label | Caption=”增加端口” |
Command1 | command | Caption=”添加” |
Command2 | command | Caption=”监听” |
Command3 | command | Caption=”退出” |
Listports | Listbox | 无 |
TxtLog | Richtextbox | 无 |
Command2.Caption = "监听"
End If
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
txtLOG.Text = "日志:" & vbCrLf
NOW_OUT = 1
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Load Winsock2(NOW_OUT) ''加载建立连接的Winsock2数组控件
Winsock2(NOW_OUT).Accept requestID ''建立连接
Winsock1(Index).Close
Winsock1(Index).Listen ''Winsock1继续监听
NOW_OUT = NOW_OUT + 1 ''连接的控件累加
myAddLog "来自" & Winsock1(Index).RemoteHostIP & "连接到本地端口:" & Winsock1(Index).LocalPort
''显示捕获的连接
End Sub
Private Sub Winsock2_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Winsock2(Index).GetData tmpstr ''通过Getdata捕获数据
myAddLog "来自" & Winsock2(Index).RemoteHostIP & "的数据:" & tmpstr ''显示捕获的数据
End Sub
Sub myAddLog(tmptext As String) ''加入日志
tmptext = tmptext & vbCrLf
txtLOG.SelStart = Len(txtLOG.Text)
txtLOG.SelText = tmptext
End Sub