Results 1 to 2 of 2

Thread: BroadCast message from Linux to windows using QUDPsocket

  1. #1
    Join Date
    Mar 2009
    Location
    India
    Posts
    8
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default BroadCast message from Linux to windows using QUDPsocket

    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 

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: BroadCast message from Linux to windows using QUDPsocket

    You could try copying the broadcast sender example. Use Wireshark to sniff packets and test if they arrive on your host. Check the Windows firewall which can get in the way.

Similar Threads

  1. QUdpsocket send and receive broadcast in linux
    By danics in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2015, 11:26
  2. QUdpSocket & broadcast & Windows7
    By xoz in forum General Programming
    Replies: 1
    Last Post: 27th October 2011, 10:08
  3. Using QUdpSocket to detect peripheral via a broadcast
    By Eos Pengwern in forum Qt Programming
    Replies: 4
    Last Post: 9th November 2010, 11:21
  4. QUdpSocket broadcast to multiple processes
    By tomschuring in forum Qt Programming
    Replies: 1
    Last Post: 30th September 2010, 01:33
  5. Qt/S60 QUdpSocket broadcast problem
    By harnen in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 13th April 2010, 22:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.