vb使用Winsock控件。

2024-10-28 10:26:58
推荐回答(6个)
回答1:

以下程序是实际使用过的。
Dim Auth as Boolean

Private Sub Form_Load()
... ... ... ...
Auth = False
' 监听1000端口
winSock1.LocalPort = 1000
If winSock1.State <> sckClosed Then winSock1.Close
winSock1.Listen
... ... ... ...
End Sub

Private Sub winSock1_ConnectionRequest(index As Integer, ByVal requestID As Long)
' 建立连接

If winSock1.State <> sckClosed Then winSock1.Close
winSock1.Accept requestID

End Sub

Private Sub winSock1_DataArrival(index As Integer, ByVal bytestotal As Long)
' 接收数据,判断是否是123,断开连接,或保持连接,显示远端IP
Dim RecData As String
winSock1.GetData RecData
if Auth then
Else
if RecData <> "123" Then
winSock1.close
winSock1.Listen
Auth = False
Else
Auth = True
Text1.Text = winSock1.RemoteHostIP
End if
End If
End Sub

回答2:

MSDN里面有详细教程,还是中文的

回答3:

oooo

回答4:

这个复制MSDN都可以啊

回答5:

很有意义

回答6:

你这流程描写得很完整啊,难到是不会编码?