客户端:
Dim port As Integer
Private Sub Command1_Click()
If Winsock1.State = 7 Then
'Winsock1.Connect
Dim send As String
send = Text2.Text
Winsock1.SendData send
End If
End SubPrivate Sub Form_Load()
Winsock1.Protocol = sckTCPProtocol
Winsock1.LocalPort = 10
Winsock1.RemoteHost = "192.168.1.6"
Winsock1.RemotePort = 10
Winsock1.Connect
End SubPrivate Sub winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Winsock1.GetData s
Text1.Text = s
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End SubPrivate Sub Winsk_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim str As String
Dim i As Integer
MsgBox "aaa"
If Index = 0 Then
For i = 0 To max_sessions
With Winsock1
If .State = sckClosed Then
.Accept requestID
Exit For
End If
End With
Next
End If
End Sub
______________________________________________________________________________________
服务端
Private Sub Form_Load()
Winsock1.Protocol = sckTCPProtocolWinsock1.LocalPort = 10
Winsock1.Listen
End SubPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long) '取得数据时发生Dim Tmp As StringWinsock1.GetData Tmp, vbString '取得数据Tmp = "对方位址:" + Winsock1.RemoteHostIP + "发言内容为-->" + Tmptxtmess.Text = Tmp + Chr$(13) + Chr$(10) + txtmess.TextEnd SubPrivate Sub Command1_Click()
MsgBox Winsock1.State '发送信息
If Winsock1.State = 7 Then
Winsock1.SendData txtsend.Text
End If
End Sub