Results 1 to 6 of 6

Thread: VB - Client/Server Example

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    VB - Client/Server Example

    VB Code:
    1. 'Client code
    2. Dim str As String
    3. Private Sub Command2_Click()
    4. Winsock1.SendData "|MESSAGE|" & Text2.Text
    5. End Sub
    6.  
    7. Private Sub Command1_Click()
    8. Winsock1.Connect Text1.Text, "1001"
    9. End Sub
    10.  
    11.  
    12. 'Server code
    13. Dim str As String
    14.  
    15. Private Sub Form_Load()
    16. Winsock1.LocalPort = 1001
    17. Winsock1.Listen
    18. End Sub
    19.  
    20. Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    21. If Winsock1.State <> closed Then Winsock1.Close
    22. Winsock1.Accept requestID
    23. End Sub
    24.  
    25. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    26. Winsock1.GetData str
    27. If InStr(1, str, "|MESSAGE|") <> 0 Then
    28. message = Mid$(str, "10", Len(str))
    29. Text1.Text = message
    30. End If
    31. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: VB - Client/Server Example

    It will be helpful, if you provide some description...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    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.
    Last edited by whatsup; Jan 11th, 2010 at 07:32 AM.

  4. #4

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: VB - Client/Server Example

    Quote Originally Posted by akhileshbc View Post
    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 View Post
    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.
    Last edited by Nightwalker83; Jan 11th, 2010 at 08:46 PM.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: VB - Client/Server Example

    Quote Originally Posted by Nightwalker83 View Post
    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.)

  6. #6

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: VB - Client/Server Example

    Quote Originally Posted by whatsup View Post
    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.

    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.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width