给你们个参考吧 A TCP client actively initiates a connection to a remote machine. Set the RemoteHost and RemotePort property. Then, call the Connect method, as shown here.TCP1.RemoteHost = 搄[email protected]? TCP1.RemotePort = 7 ?the echo port TCP1.ConnectWhen the connection has been established successfully, a Connect event occurs. If the remote host rejected the connection, a Error event occurs.Private Sub TCP1_Connect() StatusBar1.status = 揅onnected? End SubPrivate Sub TCP1_Error(Number As Integer, Description As String, Scode As Long, Source As String, HelpFile As String, HelpContext As Long, CancelDisplay As Boolean) StatusBar1.status = Number & ?- ?& Description CancelDisplay = True End SubAfter a connection has been established, use the SendData method to stream data to a remote machine. A DataArrival event occurs when there is incoming data. Use the Close method to terminate the connection, as illustrated in the following code:Private Sub btnSend_Click() TCP1.Send 揗y name is Mary.? End SubPrivate Sub TCP1_DataArrival(ByVal bytesTotal As Long) Dim data As Variant TCP1.GetData data,vbString ?retrieve data txtRecv = data ?update display TCP1.Close ?close the connection End Sub
A TCP client actively initiates a connection to a remote machine. Set the RemoteHost and RemotePort property. Then, call the Connect method, as shown here.TCP1.RemoteHost = 搄[email protected]?
TCP1.RemotePort = 7 ?the echo port
TCP1.ConnectWhen the connection has been established successfully, a Connect event occurs. If the remote host rejected the connection, a Error event occurs.Private Sub TCP1_Connect()
StatusBar1.status = 揅onnected?
End SubPrivate Sub TCP1_Error(Number As Integer, Description As String, Scode As Long, Source As String, HelpFile As String, HelpContext As Long, CancelDisplay As Boolean)
StatusBar1.status = Number & ?- ?& Description
CancelDisplay = True
End SubAfter a connection has been established, use the SendData method to stream data to a remote machine. A DataArrival event occurs when there is incoming data. Use the Close method to terminate the connection, as illustrated in the following code:Private Sub btnSend_Click()
TCP1.Send 揗y name is Mary.?
End SubPrivate Sub TCP1_DataArrival(ByVal bytesTotal As Long)
Dim data As Variant
TCP1.GetData data,vbString ?retrieve data
txtRecv = data ?update display
TCP1.Close ?close the connection
End Sub