Results 1 to 8 of 8

Thread: [VB6] Multiple UDP Connections

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    84

    [VB6] Multiple UDP Connections

    I'm using this UDP Server & Client Code. Any way to make it accept multiple connections at once?

    CLIENT:
    Code:
    Option Explicit
    
    Private Sub cmdGO_Click()
        txtHost.Text = Trim$(txtHost.Text)
        txtPort.Text = Trim$(txtPort.Text)
        
        If Len(txtHost.Text) > 0 And Len(txtPort.Text) > 0 And _
            IsNumeric(txtPort.Text) And Len(txtData.Text) > 0 Then
            
            sckClient.RemoteHost = txtHost.Text
            sckClient.RemotePort = CInt(txtPort.Text)
            sckClient.Bind 1024
            
            sckClient.SendData txtData.Text
        End If
        
    End Sub
    SERVER:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        sckServer.Protocol = sckUDPProtocol
        sckServer.LocalPort = 3794
        sckServer.Bind 3794
        Me.Caption = "Server - OPEN"
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        sckServer.Close
    End Sub
    
    Private Sub sckServer_DataArrival(ByVal bytesTotal As Long)
        Dim strData As String
        
        sckServer.GetData strData, vbString, bytesTotal
        
        Debug.Print strData
        
        Me.Caption = "DATA RECEIVED"
    End Sub

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: [VB6] Multiple UDP Connections

    There is no such thing as multiple connections when you deal with UDP, since UDP is connection-less.

    Just send data to the same port, and make sure you identify each packet properly

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    84

    Re: [VB6] Multiple UDP Connections

    I don't get how to do it.

    EDIT: Do I do like this?
    Code:
    sckServer.RemotePort = 7777
    sckServer.RemoteHost = "127.0.0.1"
    sckServer.SendData "SOMETHING HERE"
    
    'Then to send to other client
    
    sckServer.RemotePort = 7777
    sckServer.RemoteHost = "127.1.2.3"
    sckServer.SendData "HJDSH"
    Last edited by Hellomy; Apr 22nd, 2008 at 06:39 PM.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [VB6] Multiple UDP Connections

    I haven't dealt with VB6 UDP in about 10 years, but yes, it should be as simple as that. With UDP, you are just firing the data off into the ether in the hopes that it will arrive at the correct destination. It is much like sending a letter in that you put the right address on it and send it off. If the address is right, and the system is working, the message should get through. On the other hand, if the sytem goes down, or something else happens to disrupt your packet, you'll never know. The advantage to UDP is simplicity and speed, but the cost is uncertainty about receipt.
    My usual boring signature: Nothing

  5. #5
    Member
    Join Date
    May 2008
    Location
    Moorhead, MN
    Posts
    37

    Re: [VB6] Multiple UDP Connections

    With that being said would a person need to incorporate a timer in order to make sure that two packets dont get sent out simultaniously? I set up a timer that waits a half second before it sends another packet is that necessary or not really?
    -- Josh Smith
    C#, VB, PHP, SQL

  6. #6
    Fanatic Member
    Join Date
    Oct 2004
    Posts
    751

    Re: [VB6] Multiple UDP Connections

    This sounds like you should be using TCP and not UDP. UDP is only used if you don't care if the packet is out of order ect. But, TCP makes sure the packet comes in the right order.
    My Projects: [ Instant Messagener Client/Server ] [ VBPictochat ]

    My Sites:
    [ Datanethost ]
    [ Helpdesk ]

    Remember if my post was helpful then Rate This Post.

  7. #7
    Member
    Join Date
    May 2008
    Location
    Moorhead, MN
    Posts
    37

    Re: [VB6] Multiple UDP Connections

    Ah got it!
    -- Josh Smith
    C#, VB, PHP, SQL

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [VB6] Multiple UDP Connections

    A half second delay is a lifetime in UDP. I'm not as sold on TCP based on the original example. UDP is ideal for sending small packets very fast. If the amount of information is larger than the packet size, then you really could have issues, and UDP wouldn't be such a good choice. However, with TCP, packet size isn't an issue, but you have to deal with connections, and it's slower.

    There are advantages and disadvantages to both.
    My usual boring signature: Nothing

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