|
-
May 26th, 2001, 06:12 PM
#1
Thread Starter
Hyperactive Member
Free Ports
a reliable way of detecting the next free Port to communicate via winsock ?
-
May 26th, 2001, 11:38 PM
#2
Member
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.
-
May 27th, 2001, 08:45 PM
#3
Thread Starter
Hyperactive Member
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
-
May 29th, 2001, 08:24 AM
#4
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|