|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Need help retrieving a udp response after sending a udp commanddevice. 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 Jason wrote:
> I have an application where I need to send UDP network commands to You've posted your VB.NET question in a group dedicated to VB6. Try> 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. again in a group with "dotnet" in its name. "Jason" <Ja***@discussions.microsoft.com> wrote in message This is a VB6 and earlier group(VB Classic). VB.Net and all dotnet groups news:6BEFFD18-DDB0-492E-8E41-2476E201895D@microsoft.com... > data = System.Text.Encoding.UTF8.GetBytes(cmdString.ToCharArray) have either "dotnet" or "vsnet" in the group name. Please use the following group instead: news://msnews.microsoft.com/microsoft.public.dotnet.languages.vb 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 |
|||||||||||||||||||||||