Determining if UDP port is bound
Determining if UDP port is bound
Determining if UDP port is bound
Determining if UDP port is bound
Determining if UDP port is bound
Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound
Determining if UDP port is bound Determining if UDP port is bound
Determining if UDP port is bound
Go Back  Xtreme Visual Basic Talk > > > Determining if UDP port is bound


Reply
 
Thread Tools Display Modes
  #1  
Old 07-07-2012, 01:20 PM
RealityRipple's Avatar
RealityRipple RealityRipple is offline
Contributor
 
Join Date: Apr 2004
Location: Nipomo, California
Posts: 456
Default Determining if UDP port is bound


Scenario: A range of allowed ports is given, for example 1000 to 1009. Multiple connections are allowed, but each must be on its own port, and no specific order per connection is defined or guessable.

Annoying Try/Catch solution:

Code:
Private Sub GetEndPoint(Host As IPAddress, Optional Port As Integer = 1000) If Host IsNot Nothing Then udpEndPoint = New IPEndPoint(Host, Port) Try If Not sckUDP.Bind(udpEndPoint) Then GetEndPoint(Host, Port + 1) Catch ex As Exception GetEndPoint(Host, Port + 1) End Try End If End Sub

Call:
Code:
Dim hostIP As Net.IPAddress = Array.Find( Dns.GetHostEntry(Dns.GetHostName).AddressList, Function(ipList As IPAddress) ipList.AddressFamily = AddressFamily.InterNetwork) GetEndPoint(hostIP)

Question:
Is there a clean way to detect if the port is bound without relying on error handling? Something like "netstat -a -p UDP"?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Determining if UDP port is bound
Determining if UDP port is bound
Determining if UDP port is bound Determining if UDP port is bound
Determining if UDP port is bound
Determining if UDP port is bound
Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound Determining if UDP port is bound
Determining if UDP port is bound
Determining if UDP port is bound
 
Determining if UDP port is bound
Determining if UDP port is bound
 
-->