UDP Blues

  • Thread starter Thread starter Frank Rizzo
  • Start date Start date
F

Frank Rizzo

I am trying to send a UDP packet out over the internet to a device.
This device is NOT on a local network or LAN or WAN. Just a random IP
address on the internet somewhere.

For whatever reason, the UDP message does not arrive there the first
time I send it (after starting the app). It arrives fine for any
attempt afterwards, but never the first time.

What could the problem? I am kind of new to UDP, so I am at a loss. Do
I perhaps have to establish a route to the IP address or something like
(I am grasping, I know).

Meanwhile, if I send a message to a device on a local network, the
messages get there every time. Here is the code I use to send a message:

Socket sockUDP = New Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp)

Dim sendBytes As Byte() = Encoding.ASCII.GetBytes(Data)
Dim IpEndPoint As New IPEndPoint(IPAddress.Parse(Host), Port)

sockUDP.Connect(IpEndPoint)
sockUDP.SendTo(sendBytes, 0, sendBytes.Length, SocketFlags.None, IpEndPoint)

Thanks.
 
I assume it has something to do with packetloss since the packets arrive ok
on your LAN. Regardless of what's causing the packet to be dropped...when
using UDP, you HAVE to write your code assuming there will be packetloss.
If it is essential that your packet be received, you have to have the device
on the other end acknowledge receiving it. Then, if you don't get a reply,
you just keep resending it periodically until you do.

Note that I've written several UDP apps...but none in C#. However, the
above still applies.

HTH
-sb
 
I think we would need to know more about what it is sending it to. You may have a firewall issue. You may have a
router issue. You may have an issue on the receiving machine.

I'd start with putting a sniffer on the other machine to see if the packet is getting there on the first try. You may
also want to analyze the first two packets that are sent out from your local machine. Check your firewall logs on the
receiving machine.
 
Carl,

Basically I am sending a packet to a wireless modem on the TMobile
network. There isn't a firewall issue, because I don't have a firewall.
And I know that the data isn't arriving because I have a sniffer
cable connected to the actual device and I don't see the data.

However, the sample vb6 app that comes with the device sends the data
fine. They are using a 3rd party component (dart, I believe) to send
UDP data, so I don't have access to the source.
 
Frank said:
I am trying to send a UDP packet out over the internet to a device. This
device is NOT on a local network or LAN or WAN. Just a random IP
address on the internet somewhere.

For whatever reason, the UDP message does not arrive there the first
time I send it (after starting the app). It arrives fine for any
attempt afterwards, but never the first time.

What could the problem? I am kind of new to UDP, so I am at a loss. Do
I perhaps have to establish a route to the IP address or something like
(I am grasping, I know).

Meanwhile, if I send a message to a device on a local network, the
messages get there every time. Here is the code I use to send a message:

Socket sockUDP = New Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp)

Dim sendBytes As Byte() = Encoding.ASCII.GetBytes(Data)
Dim IpEndPoint As New IPEndPoint(IPAddress.Parse(Host), Port)

sockUDP.Connect(IpEndPoint)
sockUDP.SendTo(sendBytes, 0, sendBytes.Length, SocketFlags.None,
IpEndPoint)

Thanks.

Sorry about my UDP ignorance, but can you set the TTL for UDP packets? If so,
bump it up a bunch to see if it makes a difference, and if it does, then I'd
surmise that you have a (initial) routing issue.
 
Sorry about my UDP ignorance, but can you set the TTL for UDP packets?
If so, bump it up a bunch to see if it makes a difference, and if it
does, then I'd surmise that you have a (initial) routing issue.

Julie,

You might just be right. You can set the TTL using the SetSocketOption.
I'll try it out. Thanks.
 
Back
Top