Solved

Client/server through TCP/IP

Posted on 1998-07-23
1
222 Views
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?
0
Comment
Question by:chekhov
1 Comment
 
LVL 2

Accepted Solution

by:
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
      tcpServer.Listen
      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 _
      tcpServer.Close
      ' 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: "121.111.1.1") 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.
      tcpClient.Connect
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

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now