The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
TCP Sockets - Sending Image data from Python client to Hololens Server
Hi there, after weeks of frustration I was finally able to get a simple message sent from my python client to my hololens server. My ultimate goal is to get an image sent instead of just a simple string message. Is anybody experienced with doing something like this? I would really appreciate any guidance on this, I'm very new to sockets and the hololens seems to only make it more difficult.
Current code I have: https://gist.github.com/jryebread/3961e890375fcc8a64c8ac3d279ec9fa
I think the python code is sending the image correctly its just that on the receiving end I don't think I am dealing with the bytes array properly.
Best Answer
-
Optionsmtaulty ✭✭
Hi. With sockets, you often have to invent some level of protocol so that the person on the receiving end can know when to stop reading from the network.
In the case of transmitting an image over sockets, you'd perhaps first send 4 bytes containing the SIZE of the image so that the receiving end can read those 4 bytes and now it knows how much more it should expect to read before it's got the 'whole' image over the wire. That could be done by allocating one large buffer and attempting to read the whole message in one async call or it could be done by using multiple reads with a smaller buffer.
If the processor architecture isn't the same on each end of the wire then you might also have to worry about endianness.
Let me know if that helps at all - happy to sketch out some code if it'll help but I'm useless with Python so can't help on that end.
5
Answers
Hi. With sockets, you often have to invent some level of protocol so that the person on the receiving end can know when to stop reading from the network.
In the case of transmitting an image over sockets, you'd perhaps first send 4 bytes containing the SIZE of the image so that the receiving end can read those 4 bytes and now it knows how much more it should expect to read before it's got the 'whole' image over the wire. That could be done by allocating one large buffer and attempting to read the whole message in one async call or it could be done by using multiple reads with a smaller buffer.
If the processor architecture isn't the same on each end of the wire then you might also have to worry about endianness.
Let me know if that helps at all - happy to sketch out some code if it'll help but I'm useless with Python so can't help on that end.
Hey thanks so much for your explanation! Very helpful. So I'd be sending an integer value over the buffer first and then writing a while loop to iterate over the integer size? I'd love to see some example code for this.
I made a simple 2D app which you can run on your desktop which sends an image over a socket to itself and I dropped it on GitHub.
I hope that helps - you'd need to remove the 2D parts of this which are about displaying an image in XAML.
You click a button to choose an image, then another button to send/receive over the socket.
DELETED
Building the future of holographic navigation. We're hiring.
@mtaulty So it turns out I can't use your code for the hololens because it uses System.Net.Sockets which only works in Unity and does not work with the Hololens. For the Hololens you can only use the Windows.Networking.Sockets stuff. Gonna have to translate your github code to use that, because for example the hololens build code doesn't recognize TCPListener.
@jamesryebread Hi - I'm not sure what you mean here. I just ran that 2D app on the HoloLens emulator (17134) and it ran fine and a picture transferred from one side to the other. Can you not run the 2D app on HoloLens?
I was able to get it working by sending the image as a base 64 encoded string from python to the hololens. Thanks for your help and code examples!
I'm not sure how the emulator works but whenever I try to run code that uses System.Net.Sockets the Hololens/UWP complains that the library is not found. This guy talks about it in his blog post:
https://foxypanda.me/tcp-client-in-a-uwp-unity-app-on-hololens/
my code: https://gist.github.com/jryebread/2bdf148313f40781f1f36d38ada85d47