I am trying to send a broadcast message from (Raspberry Pi) linux to windows. In my linux system I am using Qt to send broadcast message and in my windows system C# is using to receive data.
I tried to send a broadcast message from my C# (Windows) program to Qt(linux) that worked fine but i didnt succeded to send a broadcast message from my linux system to windows.


Qt code to send boroadcast message

Qt Code:
  1. QUdpSocket *m_pUDPSocketSend = new QUdpSocket();
  2.  
  3. m_pUDPSocketSend->connectToHost(QHostAddress("255.255.255.255"), 4220);
  4. string strVal="I am here\n";
  5. const char * data = strVal.c_str();
  6. m_pUDPSocketSend->write(data);
To copy to clipboard, switch view to plain text mode 

My C# listener code

Qt Code:
  1. private const int listenPort = 4220;
  2.  
  3. private static void StartListener()
  4. {
  5. bool done = false;
  6.  
  7. UdpClient listener = new UdpClient(listenPort);
  8. IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
  9.  
  10. try
  11. {
  12. while (!done)
  13. {
  14. Console.WriteLine("Waiting for broadcast");
  15. byte[] bytes = listener.Receive(ref groupEP);
  16.  
  17. Console.WriteLine("Received broadcast from {0} :\n {1}\n",
  18. groupEP.ToString(),
  19. Encoding.ASCII.GetString(bytes, 0, bytes.Length));
  20. }
  21.  
  22. }
  23. catch (Exception e)
  24. {
  25. Console.WriteLine(e.ToString());
  26. }
  27. finally
  28. {
  29. listener.Close();
  30. }
  31. }
  32.  
  33. public static int Main()
  34. {
  35. for (int i = 0; i < 10; i++)
  36. {
  37. StartListener();
  38. }
  39.  
  40.  
  41.  
  42. return 0;
  43. }
To copy to clipboard, switch view to plain text mode