Playing around with a transceiver and it works great, until it actually fails ![]()
It works by sending a UDP broadcast, and then it waits for a return.
However sometimes for a variety of reason the return might not happen.
These are the cases i want to timeout, because what happens right now both
in Unity 4 and 5 is that the entire Unity thread just becomes unresponsive.
Well basically itās blocking the entire program until it receives a signal,
that is kinda silly.
I was originally looking to make a UDP listener, but without proper understanding
i so far only got a āupdateā function working. Ideally i would have a listener just
checking for udp signals, but with my current knowledge or lack of the same,
that would just make a continuously blocking program.
Here is some codeā¦
public void updateUDPStatus()
{
packetData = "send this S1, returns status";
sendUDP(packetData); // This is sendt to the UDP server, which responds with a status
UdpClient receivingUdpClient = new UdpClient(returnPort);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
try{
// PROBLEM\BLOCKING LINE BELOW
Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);// <--- THIS IS THE PART WHERE IT BLOCKS
// PROBLEM\BLOCKING LINE ABOVE
String returnData = Encoding.ASCII.GetString(receiveBytes);
myString = returnData;
for (int i = 0; i < myString.Length; i++)
{
if (myString[i] == 'S')
{
int io = i+1;
updateLight(myString[io]); // Do stuff with IO
}
}
receivingUdpClient.Close();
}
catch ( Exception e ){
Console.WriteLine(e.ToString());
}
}
Any suggestions ?
and if you suggest threading, well then Iām going to need a small example of threading,
never used it before.