Option Explicit
Private Sub Command1_Click()
If Text3.Text = "" Then
MsgBox "请输入对方IP", vbOKOnly, "提示"
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "请输入要发送的内容", vbOKOnly, "提示"
Exit Sub
End If
Winsock1.RemoteHost = Text3.Text
Dim a As String
'a = Text2.Text
Winsock1.SendData Text2.Text
Text1.Text = Text1.Text & vbCrLf & "我:" & Text2.Text
Text2.Text = ""
End Sub
Private Sub Form_Load()
Text4.Text = Winsock1.LocalIP
Text3.Text = ""
Winsock1.RemotePort = 2011远程端口
Winsock1.LocalPort = 2011本地端口
Winsock1.Bind 2011绑定端口
Text4.Text = Winsock1.LocalIP
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next '接收错误则继续执行
Dim a As String
Winsock1.GetData a
Text1.Text = Text1.Text & vbCrLf & "对方:" & a
End Sub
这里的端口是预设好的,IP是可变的,你可以自己改一下,加两个文本框就行了