VB - Client/Server Example
VB Code:
'Client code
Dim str As String
Private Sub Command2_Click()
Winsock1.SendData "|MESSAGE|" & Text2.Text
End Sub
Private Sub Command1_Click()
Winsock1.Connect Text1.Text, "1001"
End Sub
'Server code
Dim str As String
Private Sub Form_Load()
Winsock1.LocalPort = 1001
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> closed Then Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData str
If InStr(1, str, "|MESSAGE|") <> 0 Then
message = Mid$(str, "10", Len(str))
Text1.Text = message
End If
End Sub
Re: VB - Client/Server Example
It will be helpful, if you provide some description... :)
Re: VB - Client/Server Example
wow, i understood what he did.
now i have to check if this connection method realley work.
i hope yesssssssssssssssss.
my current method (that i learn here), is to set the remote server like this
winsck.RemoteHost = Text1.Text
winsck.RemotePort = 1001
EDIT: i just checked this.
both methods seem to make the same task.
doesn't work for me when trying with 2 virtual machines.
hope it'll work on real machines.
Re: VB - Client/Server Example
Quote:
Originally Posted by
akhileshbc
It will be helpful, if you provide some description... :)
The code sends a message as text from the client to the server then the server displays the message in a textbox.
Quote:
Originally Posted by
whatsup
wow, i understood what he did.
now i have to check if this connection method realley work.
i hope yesssssssssssssssss.
my current method (that i learn here), is to set the remote server like this
winsck.RemoteHost = Text1.Text
winsck.RemotePort = 1001
EDIT: i just checked this.
both methods seem to make the same task.
doesn't work for me when trying with 2 virtual machines.
hope it'll work on real machines.
1. What you need is a winsock control named "Winsock1" for both projects.
2. Two textboxes and two command buttons for the client.
3. A textbox for the server.
4. Use the above code in the appropriate projects.
By the way this code is nearly 7 years old.
Re: VB - Client/Server Example
Quote:
Originally Posted by
Nightwalker83
1. What you need is a winsock control named "Winsock1" for both projects.
2. Two textboxes and two command buttons for the client.
3. A textbox for the server.
4. Use the above code in the appropriate projects.
By the way this code is nearly 7 years old.
maybe you didn't understand (or i didn't).
I know and can send/recieve files when the sender and reciever on the same machine.
but when i tried to put the sender on virtual machine 1
and the reciever on virtual machine 2
it didn't work.
maybe because the both machines have the same external IP.
so i'll have to check this with 2 different computers that have different
external IP.
(unless someone tell me if it can be done on the same IP.)
Re: VB - Client/Server Example
Quote:
Originally Posted by
whatsup
maybe you didn't understand (or i didn't).
I know and can send/recieve files when the sender and reciever on the same machine.
The description was actually in response to akhileshbc's post, I should have mentioned that.
Quote:
but when i tried to put the sender on virtual machine 1
and the reciever on virtual machine 2
it didn't work.
maybe because the both machines have the same external IP.
so i'll have to check this with 2 different computers that have different
external IP.
(unless someone tell me if it can be done on the same IP.)
Last I tried it worked for me on the same machine (not virtual machine). Try using the local ip i.e 127.0.0.1 and see if that works. Unfortunately, I no longer have the source code on my computer and vb 6.0 is acting up from me on Vista.