The existence of coroutines leads me to believe that all user code in Unity is single threaded. If that is the case, does anyone know how to get around the blocking UdpClient.Receive() method? If the code were multi-threaded, then I would have a separate thread reading UDP packets and sending update messages to a controller object in another thread. Barring that, I would probably set an alarm (like a signal) to timeout the Receive() method. Anyone have any ideas how to receive UDP packets in real time without interfering with all the object updates?
While unity doesn't run any of the game code in seperate threads, there is nothing that prevents you from creating your own threads and running your network code from in there. http://msdn.microsoft.com/library/d...html/frlrfSystemThreadingThreadClassTopic.asp
You could also check out the non-blocking socket functions. I found it easier just to spawn new threads and use the blocking ones, though. One gotcha is that you must shut those threads down in the OnApplicationQuit method. Although it was really funny seeing the network updates still happen after I clicked stopped within the editor... -Jon
Joachim -- Excellent; very good to see multithreading is supported. Jon -- I couldn't find a non-blocking UDP receive for .NET. (Microsoft's .NET docs aren't exactly the most user friendly...) Can you post a link for the docs to such a method?
http://msdn.microsoft.com/library/d...tml/frlrfsystemnetsocketssocketclasstopic.asp You can get at the underlying Socket of the higher level interface: http://msdn.microsoft.com/library/d...fSystemNetSocketsUdpClientPropertiesTopic.asp -Jon