For several weeks I’ve been working on a web app in Unity, trying to get it to connect to a Python-based server. There was some initial success (passing strings with the lowest-level networking classes in Mono [oh how I loath byte arrays :shock: ]), but I really need to pass textures back and forth between these two.
Using TcpClient hasn’t worked; Unity just doesn’t connect to the Python script (which was running in the console, not IDLE).
Is there some way to pass texture data between a Unity webapp and a Python server? Getting desperate here
I’ve been reading the .NET documentation over and over and over and over… and over again.
(Has something like this ever been done before? I looked, but haven’t found such a thing…)
Read the documentation on security sandbox in the webplayer. I’m pretty sure thats what causing the problem for you here.
Reading the .NET docs over and over and over won’t help if you ignored those requirements as no connection is ever made at all actually
Ah, I did that X]
That DID cause problems initially, but I used the bundled echo program. I know for certain that the security fetch is working fine.
[Edit:]
[The error I get is a generic “cannot connect” error, and not a “Security Prefetch Failed” error]
I should clarify, there’s ONE condition under which Unity connects with Python; when the Mono socket is a raw socket.
That’s right, I can still pass byte arrays along.
If there’s a way to load a texture from a byte array of a png/jpg file, and then to convert a texture to a byte array to send back to Python, then I could live with that. XD Creating my own network protocol isn’t the end of the world…
Anyone know how to do these byte-array conversions in Unity 3D? :B
(If I’m asking something impossible, please let me know)
You can use Texture2D.LoadImage to decode the byte stream and the complementary EncodeToPNG to encode a texture (there’s no equivalent EncodeToJPG function, unfortunately).
You can also use the WWW class to POST / GET textures thru python HTTP webserver.