Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using UDP Services
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
Using UDP Services
Miscellaneous
Thread ID:
00970065
Message ID:
00970065
Views:
56
Hi Guys,
I am tring to run the example with the title "Using UDP Services" found in the M$ docs.
I created two console apps, one UdpSender and one UdpListener using the code in the document.

The only things I changed was to change (in both apps):
GroupAddress = IPAddress.Parse("192.168.50.10");
GroupPort = 30718;
And instead for passing the message to send in the args I always send the following message:
byte[] bytes = new byte[4];
bytes[0] = 0x00;
bytes[1] = 0x00;
bytes[2] = 0x00;
bytes[3] = 0xF6; //F6 : Querry of firmware version	
Now the reason I changed the IP address to 192.168.50.10 is because I have a second network card on my computer with that IP address and that networkcard is attached to a switch and the switch is connected to two devices that will send out a packet if they receive 0x00,0x00,0x00,0xF6 on port=30718. The two devices have the IP addresses 192.168.50.90 and 192.168.50.100.

When I run the listener app, it says it is listening but it never gets any further than:
byte[] bytes = listener.Receive( ref groupEP);
The sender app seems like it works the way it should.

Now I know that my two devices can talk because the following code works but I wanted to attemt using UDP Services:
private void SendCommand(System.Byte[] bMsg)
{
const System.Int16 iPort = 30718;// using port 0x2711 causes problem to hang up, no exception is thrown
System.Net.IPAddress ip1;
System.Byte[] buffer = new byte[1024];
System.Int32 iRecBytes = 0;

try
{
  ip1 = System.Net.IPAddress.Parse(this.txtIP1.Text); //this.txtIP1.Text=192.168.50.255
}
catch(Exception ex)
{
  MessageBox.Show(ex.ToString(),"Exception caught trying to parse IP1");
  return;
}

// Record the data packet sent
this.txtSend.AppendText("Msg Sendt("+bMsg.Length.ToString()+"): ");
for (int i = 0 ; i<bMsg.Length ; i++)
{
 this.txtSend.AppendText(bMsg[i]	+ " ");
}
this.txtSend.AppendText(Environment.NewLine);


try
{
  IPEndPoint ipEP = new IPEndPoint(ip1,iPort);
				
  Socket s = new Socket(ipEP.Address.AddressFamily,	SocketType.Dgram,	ProtocolType.Udp);

  s.SendTo(bMsg, 0, bMsg.Length, SocketFlags.None, ipEP);
				
  IPEndPoint senderEP = new IPEndPoint(IPAddress.Any, iPort);
  EndPoint tempRemoteEP = (EndPoint)senderEP;
				
  for (int j=0;j<2;j++) //do it twice cuz i know i have 2 sboxes if i loop more than twice it hangs
  {

    iRecBytes = s.ReceiveFrom(buffer, 0, 1024, SocketFlags.None, ref tempRemoteEP);

    MessageBox.Show(tempRemoteEP.ToString(),iRecBytes.ToString());
				
    // Record the data packet received
    this.txtStatus.AppendText("Received the following message ("+iRecBytes.ToString()+"bytes) : " + Environment.NewLine);

    for(int i = 0; i < iRecBytes;i++)
    {
      this.txtStatus.AppendText(buffer[i]	+ " ");

    }

    this.txtStatus.AppendText(Environment.NewLine+Environment.NewLine);
  }			
  catch(SocketException exp)
  {
    this.txtStatus.AppendText(String.Format(Environment.NewLine	+ "SocketException: {0}" + Environment.NewLine, exp));
  }
  catch(Exception ex)
  {
    this.txtStatus.AppendText(String.Format(Environment.NewLine	+ ex.ToString()));
  }
}
Any thoughts would be appreciated.

Thanks,
Einar
Semper ubi sub ubi.
Reply
Map
View

Click here to load this message in the networking platform