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
Code:
m_pUDPSocketSend
->connectToHost
(QHostAddress("255.255.255.255"),
4220);
string strVal="I am here\n";
const char * data = strVal.c_str();
m_pUDPSocketSend->write(data);
My C# listener code
Code:
private const int listenPort = 4220;
private static void StartListener()
{
bool done = false;
UdpClient listener = new UdpClient(listenPort);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
try
{
while (!done)
{
Console.WriteLine("Waiting for broadcast");
byte[] bytes = listener.Receive(ref groupEP);
Console.WriteLine("Received broadcast from {0} :\n {1}\n",
groupEP.ToString(),
Encoding.ASCII.GetString(bytes, 0, bytes.Length));
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
listener.Close();
}
}
public static int Main()
{
for (int i = 0; i < 10; i++)
{
StartListener();
}
return 0;
}
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.