两台电脑必须用两个Winsock控件。我把你的源码改进了一下:
Private Sub cmdConnection_Click()
With wskSend
.RemotePort = 3839
Dim IP As String
IP = InputBox("请输入要连接的IP", "输入的IP")
.RemoteHost = IP
If IP <> "" Then
cmdConnection.Caption = "重新连接"
cmdClean.Enabled = True
cmdSend.Enabled = True
End If
End With
End Sub
Private Sub cmdClean_Click()
Dim i As Integer
i = MsgBox("确定清除聊天记录?", vbYesNo + vbQuestion, "提示您!")
If i = vbYes Then
txtGet.Text = ""
End If
End Sub
Private Sub cmdSend_Click()
wskSend.SendData txtSend.Text
txtGet.Text = txtGet.Text & Chr$(13) & Chr$(10) & "自己说:" & txtSend.Text
End Sub
Private Sub Form_Load()
With wskGet
.Protocol = sckUDPProtocol
.LocalPort = 3839
.Bind 3839
End With
wskSend.Protocol = sckUDPProtocol
cmdClean.Enabled = False
cmdSend.Enabled = False
End Sub
Private Sub wskGet_DataArrival(ByVal bytesTotal As Long)
Dim Text As String
wskGet.GetData Text, vbString
txtGet.Text = txtGet.Text & Chr$(13) & Chr$(10) & "对方说:" & Text
End Sub
首先是逻辑错误
Text2.Text = Text2.Text + Chr$(13) + Chr$(10) + "我说:" + Text1.Text '加到聊天记录中
Wskclient.SendData Text2.Text
先扫描你输入的内容然后才能发生,低级错误。
额,,,不懂这是专业问题