Networking systems conflict
Building a TCP/UDP protocol to exchange data from Unity supported environment to Universal Windows Platform is not a straightforward process. You should expect, we did not though, a lot of incompatibilities due to the different networking systems that are supported by each.
Developing a networking capabilities in Unity environment can be done using several libraries like Unet, System.Net and many other Unity plugin libraries to network with different applications. At first stage, we used NatNet library provided by OptiTrack to network with Motive.
However, Universal Windows Platform doesn't support, all? we don't know!, most of these libraries. It uses its own networking library Windows.Networking, which is ironically is not supported in Unity!
Building a TCP/UDP protocol to exchange data from Unity supported environment to Universal Windows Platform is not a straightforward process. You should expect, we did not though, a lot of incompatibilities due to the different networking systems that are supported by each.
Developing a networking capabilities in Unity environment can be done using several libraries like Unet, System.Net and many other Unity plugin libraries to network with different applications. At first stage, we used NatNet library provided by OptiTrack to network with Motive.
However, Universal Windows Platform doesn't support, all? we don't know!, most of these libraries. It uses its own networking library Windows.Networking, which is ironically is not supported in Unity!
Both editors will complain about unknown sockets definitions. To make it works, wrap each platform specification in #if Unity_Editor #else (for UWP). That will make the compiler ignore the editor that is not under consideration. For example:
#if UNITY_EDITOR
System.Net.Sockets.TcpClient client;
#endif
#if !UNITY_EDITOR
Windows.Networking.Sockets.StreamSocket socket;
#endif
System.Net.Sockets.TcpClient client;
#endif
#if !UNITY_EDITOR
Windows.Networking.Sockets.StreamSocket socket;
#endif
UDP protocol support on Hololens
We are streaming data that is not really harmful to loose some packages at the expense of performance. Receiving data over UDP protocol is faster since packages don not require a delivery ack message. UWP provides DatagramSocket to transfer data over UDP protocol. However, Hololens drops any incoming packages over UDP! there are a lot of discussions in Unity and Hololens communities about the issues and there is no solution so far. We turned to TCP protocol for data receiving to handle this problem. The frame rate still good though.
Hololens Emulator
Luckily, we have the real device. If you're trying to run your application using the Hololens emulator, from home for example, there are some painful errors related to the registries and the buffer size that prevent the debugging. After several attempts, it finally runs and then traps into the same problem over and over!
We are streaming data that is not really harmful to loose some packages at the expense of performance. Receiving data over UDP protocol is faster since packages don not require a delivery ack message. UWP provides DatagramSocket to transfer data over UDP protocol. However, Hololens drops any incoming packages over UDP! there are a lot of discussions in Unity and Hololens communities about the issues and there is no solution so far. We turned to TCP protocol for data receiving to handle this problem. The frame rate still good though.
Hololens Emulator
Luckily, we have the real device. If you're trying to run your application using the Hololens emulator, from home for example, there are some painful errors related to the registries and the buffer size that prevent the debugging. After several attempts, it finally runs and then traps into the same problem over and over!