Home All Groups Group Topic Archive Search About

Need help retrieving a udp response after sending a udp command

Author
1 Jul 2009 8:11 PM
Jason
I have an application where I need to send UDP network commands to a network
device.  I'm able to send the commands successfully and see the network
device respond to them on it's front panel.  However, I can't see the UDP
response that it sends back on the wire.

I'm using the following code as a quick comm test:

Public Sub SendCommand()
        Dim dstAddress As IPAddress
        dstAddress = IPAddress.Parse("10.15.2.21")

        Dim udpClient As New UdpClient(9401)
        udpClient.Connect(dstAddress, 2202)

        Dim cmdString As String
        Dim data() As Byte

        Dim rxData() As Byte
        Dim RemoteIPEndPoint As New IPEndPoint(IPAddress.Any, 0)


        cmdString = "Turn On"
        data = System.Text.Encoding.UTF8.GetBytes(cmdString.ToCharArray)
        udpClient.Send(data, data.Length)

        rxData = udpClient.Receive(RemoteIPEndPoint)
        Dim Text As String = System.Text.Encoding.ASCII.GetString(rxData)
        Console.WriteLine(">> " & Text & " from: " &
RemoteIPEndPoint.Address.ToString & ": " & RemoteIPEndPoint.Port & vbCrLf)
    End Sub

The remote device is located at 10.15.2.21 and is listening for commands on
udp/2202.  My udpclient sends a command string to the device from my local IP
address on port 9401.  .036 seconds after I send the command, the remote
device responds on a random port and sends the response to my local machine
on udp/9401 (in response to my outbound message.)  I can verify this
communication using wireshark.

My problem is that I'm not seeing the response via the udpclient in code. 

Can anyone offer suggestions on what I'm missing here?  Am I getting into a
race condition where my code doesn't start listening for a response until
after the device has already sent it?  If that's the case, I'd welcome
suggestions on the best way to create a full time udp listener on a different
thread and be able to respond to inbound data events.

Thanks,

Jason

Author
1 Jul 2009 8:37 PM
Jim Mack
Jason wrote:
> I have an application where I need to send UDP network commands to
> a network device.  I'm able to send the commands successfully and
> see the network device respond to them on it's front panel.
> However, I can't see the UDP response that it sends back on the
> wire.

You've posted your VB.NET question in a group dedicated to VB6. Try
again in a group with "dotnet" in its name.

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"
Author
1 Jul 2009 8:40 PM
Nobody
"Jason" <Ja***@discussions.microsoft.com> wrote in message
news:6BEFFD18-DDB0-492E-8E41-2476E201895D@microsoft.com...
>        data = System.Text.Encoding.UTF8.GetBytes(cmdString.ToCharArray)

This is a VB6 and earlier group(VB Classic). VB.Net and all dotnet groups
have either "dotnet" or "vsnet" in the group name. Please use the following
group instead:

news://msnews.microsoft.com/microsoft.public.dotnet.languages.vb
Author
2 Jul 2009 9:50 AM
Colbert Zhou [MSFT]
Hi Jason,

Here are two nice articles as well as sample projects about how to do UDP
sending and recieving using different threads in VB.NET,
http://www.codeproject.com/KB/IP/UDP_Send_Receive.aspx
http://www.codeproject.com/KB/vb/UDP_Client_Server.aspx

For VB.NET questions, you are encouraged to post in
microsoft.public.dotnet.languages.vb newsgroup as "Nobody" mentions.


Best regards,
Colbert Zhou