UDPClient listen to any address, any port

  • Thread starter Thread starter =?ISO-8859-1?Q?=22D=2E_Andr=E9_Dhondt=22?=
  • Start date Start date
?

=?ISO-8859-1?Q?=22D=2E_Andr=E9_Dhondt=22?=

In VB.NET 2003, is there a way to create a System.Net.Sockets.UDPClient
to listen to any address AND any port?

I can get it to listen to any address, but only if I specify a port (for
example, port 12345):

'-----------
Dim udpClient as New Sockets.UdpClient(12345)
Dim ipEndPoint as New IPEndPoint(IPAddress.Any, 0)
Dim receiveBytes as Byte()

receiveBytes = udpClient.Receive(ipEndPoint)
'-----------
 
Use 0 (zero) as your port.
This way, all the ports will be listen to

Regards

Dieter Boden-Schelfthout
 
Dieter--zero doesn't get it to listen to all ports--even if I ctype it
as a short to get it to recognize it as a port in the first place:
Dim udpClient as New Sockets.UDPClient(CType(0,Short))

.... broadcasts to that udp client are not received. If I specify
another port, however, it can receive:
Dim udpClient as New Sockets.UDPClient(CType(12345,Short))

My broadcasting happens as follows:
Dim udpClient as New UDPClient
Dim ipEndPoint as New IPEndPoint(IpAddress.Broadcast, 12345)
Dim sendBytes as [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")
Dim sentBytes as Integer
sentBytes = udpClient.Send(sendBytes, sendBytes.Length, ipEndPoint)
 
As I am coming to believe, UDPClient will listen to only one port for
the specified NIC--and as soon as my app binds to a port, the app has
exclusive use of the port until it releases it. Can anyone confirm or
refute this?

If the above is true, then I can't listen to all ports with one
UDPClient or even one socket.


D. André Dhondt said:
Dieter--zero doesn't get it to listen to all ports--even if I ctype it
as a short to get it to recognize it as a port in the first place:
Dim udpClient as New Sockets.UDPClient(CType(0,Short))

.... broadcasts to that udp client are not received. If I specify
another port, however, it can receive:
Dim udpClient as New Sockets.UDPClient(CType(12345,Short))

My broadcasting happens as follows:
Dim udpClient as New UDPClient
Dim ipEndPoint as New IPEndPoint(IpAddress.Broadcast, 12345)
Dim sendBytes as [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")
Dim sentBytes as Integer
sentBytes = udpClient.Send(sendBytes, sendBytes.Length, ipEndPoint)
Use 0 (zero) as your port.
This way, all the ports will be listen to

Regards

Dieter Boden-Schelfthout
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top