Results 1 to 4 of 4

Thread: Free Ports

  1. #1

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261

    Free Ports

    a reliable way of detecting the next free Port to communicate via winsock ?
    - regards -
    - razzaj -

  2. #2
    It works great with an array of winsock controls.
    Have the main one winsock as Winsock1(0) <-- index 0

    Then load one or more of the control.
    Whenever you want the next available local port
    it'd be winsock1(0).localport


    or just loop through about 10 winsock controls and try to connect on each port, if the port isn't connected or error then you'll be able to connect to it.

  3. #3

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    i didnt quite understand. you mean the Next freePort is the Port of the Zero-indexed Winsock ?? or does winsock1(0).localport automatically returns the Next free Port ???


    Then load one or more of the control.
    Whenever you want the next available local port
    it'd be winsock1(0).localport
    - regards -
    - razzaj -

  4. #4
    Addicted Member csammis's Avatar
    Join Date
    Mar 2001
    Location
    /dev/null
    Posts
    226
    Here's some code that might do what you want:

    Code:
        Dim i as Long
        On Error Goto loop
        For i = 1 To 65535
            Winsock1.LocalPort = i
            Exit For
    loop:
            Err.Clear
        Next i
        ' ...whatever with the free port
    The first port it encounters without an error is the one it's assigned. I admit this is a kinda crude way to do it, and it won't translate to VB.NET, but it works for everything else
    Things I've Said:
    "Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
    "Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
    "You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"

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