Client/server through TCP/IP

Posted on 1998-07-23
Last Modified: 2013-11-13
VB5 enterprise edition comes with a sample client/server project, that displays
"Hello Visual Basic Users" when a button is clicked at the client.
How do I make this application work when the server is on a remote machine, and
all I know about it is it's IP address?
Question by:chekhov
1 Comment

Accepted Solution

seahpc earned 200 total points
ID: 1466572
you need to use the Win Socket control .
Attach is a simple code
you will need some buttons and textboxes and winsocket for it
' Server / Remote Machine Codes
' TcpServer = Socket

Private Sub Form_Load()
      ' Set the LocalPort property to an integer.
      ' Then invoke the Listen method.
      tcpServer.LocalPort = 1001
      frmClient.Show ' Show the client form.
End Sub

Private Sub tcpServer_ConnectionRequest _
(ByVal requestID As Long)
      ' Check if the control's State is closed. If not,
      ' close the connection before accepting the new
      ' connection.
      If tcpServer.State <> sckClosed Then _
      ' Accept the request with the requestID
      ' parameter.
      tcpServer.Accept requestID
End Sub

Private Sub txtSendData_Change()
      ' The TextBox control named txtSendData
      ' contains the data to be sent. Whenever the user
      ' types into the  textbox, the  string is sent
      ' using the SendData method.
      tcpServer.SendData txtSendData.Text
End Sub

Private Sub tcpServer_DataArrival _
(ByVal bytesTotal As Long)
      ' Declare a variable for the incoming data.
      ' Invoke the GetData method and set the Text
      ' property of a TextBox named txtOutput to
      ' the data.
      Dim strData As String
      tcpServer.GetData strData
      txtOutput.Text = strData
End Sub

' Client code

Private Sub Form_Load()
      ' The name of the Winsock control is tcpClient.
      ' Note: to specify a remote host, you can use
      ' either the IP address (ex: "") or
      ' the computer's "friendly" name, as shown here.
      tcpClient.RemoteHost = "RemoteComputerName"
      tcpClient.RemotePort = 1001
End Sub

Private Sub cmdConnect_Click()
      ' Invoke the Connect method to initiate a
      ' connection.
End Sub

Private Sub txtSendData_Change()
      tcpClient.SendData txtSend.Text
End Sub

Private Sub tcpClient_DataArrival _
(ByVal bytesTotal As Long)
      Dim strData As String
      tcpClient.GetData strData
      txtOutput.Text = strData
End Sub


Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
drawing animated level bar based on numbers 3 97
Macro Excel - Multiple If conditions 2 72
Python 3.5.2 32 virtualenv problems 3 39
Problem to refer to value 8 50
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question