how to use winsock to exchange data in 2 diferent exe
-
dear all this is first time for me to use winsock in vb6, i don't how to exchange data in 2 different exe, although i searched online, but i still didn't get what i expect. anyone can tell me this point--step by step. thanks a lot.
zhiyuan16 wrote:
this is first time for me to use winsock in vb6, i don't how to exchange data in 2 different exe,
There's a basic example here[^]. Best way to go would be to analyze examples, and try to build something similar.
zhiyuan16 wrote:
although i searched online, but i still didn't get what i expect. anyone can tell me this point--step by step.
That begs the question on what you're expecting, and what the requirements for the communications are.
I are Troll :suss:
-
dear all this is first time for me to use winsock in vb6, i don't how to exchange data in 2 different exe, although i searched online, but i still didn't get what i expect. anyone can tell me this point--step by step. thanks a lot.
Hi, Following sample shows the use of Winsock in vb6. Just copy, paste & Test. To Test in local mode (if currently u don't have two machines connected)
Make "yourproject.exe" & run in double instance then:
in 1 instance click Listen(Command2) And another click Connect(Command2).
Then Type text in Text3 and click on Send(Command3).'Create a new project: Add 3 TextBox, 3 CommandButton And 1 Winsock. Do not change any of them's Name.
'Paste this whole string inside your form's code window
Option Explicit
'Text1= Remote IP/MachineName; for local 127.0.0.1
'Text2= Port Number; I used 1971; you should be sure that the given port is not in use'Command1=Connect
Private Sub Command1_Click()
Winsock1.Connect Me.Text1, Me.Text2
End Sub'Command2=Start Listening
Private Sub Command2_Click()
Winsock1.LocalPort = Me.Text2
Winsock1.Listen
End Sub'Command3=Send Text
Private Sub Command3_Click()
'Text3= what you want to send
Winsock1.SendData Me.Text3.Text
'Me.Caption is used to display status
Me.Caption = "Local Send" & Me.Text3.Text
End Sub'Received text
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim AD As String
Winsock1.GetData AD
Me.Caption = "Remote: " & AD
End Sub'ConnectionRequest
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
On Error Resume Next ' Just in case there's an error, continue with next command.
Winsock1.Close ' Close any open socket (just in case).
'Must accept the request to continue
Winsock1.Accept requestID
Me.Caption = "Request accepted"
End Sub'Chat session closed
Private Sub Winsock1_Close()
Me.Caption = "Closed"
End Sub'Connected
Private Sub Winsock1_Connect()
Me.Caption = "Chat Started at " & Time
End Sub