I'm using a Raspberry Pi as a server in our network with IP: 172.20.X.X/16
The plan is to send a broadcast-message to the port 15555
. The Server will receive the message and send me his eth0-IP.
As I'm not the best in networking, I have problems to make a script that sends the IP to the broadcaster, and especially let this script get executed when the Server receives anything on port 15555
I've read some things about the command "nc" but I don't really get if that solves my problem:
https://stackoverflow.com/a/4739260/11397900
So at the moment I have 2 scripts:
Script 1 contains
#!/bin/bash
while :
do
nc -k -l 15555 > sendIP.sh
sleep 1
done
Script 2 is called sendIP and contains atm
#!/bin/bash
echo "Success"
Last but not least, my C#-Code to send a broadcast is this one:
private static string getServerIP(int port)
{
string IPString = String.Empty;
IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse("172.20.255.255"), port);
byte[] messageInbytes = Encoding.ASCII.GetBytes("Hallo");
UdpClient udpClient = new UdpClient();
udpClient.Send(messageInbytes, messageInbytes.Length, iPEndPoint);
udpClient.Client.ReceiveTimeout = 1000;
while (true)
{
try
{
var recvBuffer = udpClient.Receive(ref iPEndPoint);
break;
}
catch
{
}
}
return iPEndPoint.Address.ToString();
}
The expectation is, that on the Raspberry, there will stand "Success" in the console, and the c#- program finishes, but in reality, the Program won't get a response