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
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);
QUdpSocket *m_pUDPSocketSend = new QUdpSocket();
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);
To copy to clipboard, switch view to plain text mode
My C# listener 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;
}
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;
}
To copy to clipboard, switch view to plain text mode
Bookmarks