HOWTO: Create & Use a Client/Server Using Winsock TCP ControlsID: Q152057
|
The Internet Control Pack contains the Winsock control that allows you to connect to a remote machine and exchange data dynamically between computers in both directions. This article demonstrates the steps required to create a minimal client and server relationship for exchanging data between computers. The Winsock TCP control, a connection-based control, is used to create the client and server.
Private gSockInstance
Private Sub Form_Load()
gSockInstance = 0
TCP1(0).LocalPort = 1007
TCP1(0).Listen
End Sub
Private Sub TCP1_ConnectionRequest(Index As Integer, _
ByVal requestID As Long)
gSockInstance = gSockInstance + 1
Load TCP1(gSockInstance)
TCP1(gSockInstance).Accept requestID
End Sub
Private Sub TCP1_DataArrival(Index As Integer, ByVal bytesTotal _
As Long)
Dim vta
TCP1(Index).GetData vta, vbString
MsgBox vta, 0, "Server"
End Sub
Private Sub Command1_Click()
With TCP1
.RemoteHost = "machine name you specify"
.RemotePort = 1007
.Connect
End With
End Sub
Private Sub Command2_Click()
TCP1.SendData "This is how we begin"
End Sub
Private Sub TCP1_Connect()
If (TCP1.State = sckConnected) Then
MsgBox "connection successful"
Else
MsgBox "connection failed"
End If
End Sub
Keywords : kbnetwork kbAPI kbSDKPlatform kbVBp400 kbWinsock kbGrpNet
Version :
Platform :
Issue type :
Last Reviewed: March 10, 1999