Private Sub Form_Load()
myserver.LocalPort = 5211
myserver.bind
myserver.Listen
End Sub
Private Sub myServer_ConnectionRequest(ByVal requestID As Long)
If myserver.State <> sckClosed Then
myserver.Close
End If
myserver.Accept requestID
End Sub
Private Sub myServer_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
myserver.GetData strData
If strData = " hello " Then
MsgBox ("收到数据!")
End If
End Sub
Private Sub myServer_Close()
myserver.Close
myserver.Listen
End Sub
(2)测试
我们可以查看自己端口,来看下有没有起到相应的作用。
4,客户端程序
(1)编码
Private Sub form_Load()
myClient.RemoteHost = "127.0.0.1"
myClient.RemotePort = 5211
End Sub
Private sub cmdConnect_Click()
myClient.Connect
End sub
Private Sub cmdsenddata_Click()
myClient.SendData "hello"
End Sub
Private Sub myClient_Connect()
debug.print "success!"
end sub