发布网友 发布时间:2023-08-18 06:11
共1个回答
热心网友 时间:2024-07-02 11:24
tcpClient.RemoteHost = "192.168.1.18"去掉 tcpClient.LocalPort = Rnd,让winsock控件自动选择本机的空闲的端口
追问原先不加这个也是这个情况,现在的情况是过一段时间就可以用了,但是关闭后立即连接就会提示地址被占用,还要麻烦你了追答Option Explicit
Private Sub Command1_Click()
Winsock1.Connect
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Winsock1.SendData Text1.Text
End Sub
Private Sub Form_Load()
With Winsock1
'本地
.Protocol = sckTCPProtocol
.LocalPort = 0 'port =0 表示任意
'远程
.RemoteHost = "192.168.1.20"
.RemotePort = 8080
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
'无论Connect与否,都需关闭!
Winsock1.Close
End Sub