Texture networking

Hi everybody

I’m currently working on a network texture sender script. I’m using Max Jsp for video capture, and I send video datas with µ (I only use JitReceiveTextureAlt).

Throught localhost there is no problem, this script works perfectly and I succed on mapping the video on a plane.
However, i need to send this video to 10 computers throught the local network and even if i try with only one computer, it lags a lot …

What i wanted to do is to make an Unity instance that use JitReceiveTextureAlt and retreive a Texture2D (an array of 256 * 256 Color, so 4 values, casted into char, in order to make it faster). Next, it sends this array to network clients (script TextureServer). The clients retrieve it (with the TextureClient script) and map it on the plane.
The problem is that my scripts make Unity crash down, without prompting any error message in the console.

So there is my question : i’m already using SmartFox for player moving. Is there a way to send directly a Texture2D via SmartFox ? Or just the array i am talking about?

Sorry if I made some mistakes …

Any help would be welcome !

you can use the texture bytes for sending.

the main problem won’t go away, thats the likely incorrect code leading to the crash because you take the newly received texture and just overwrite the one on the object which would result in a never freed yet no longer used texture → massive leak.

As for the lag: nothing can be done about that. Sending 30 fps your way would result in an upstream bandwidth requirement of 7.5MB/s! (or a 100mbit connection technically, at very least)

What you will likely want / have to do is get the image thats sent in from the cam in its compressed form and send the bytes of that and then make it a texture on the other side.
that way the requirements will drop by a factor of 10 to 20 depending on the format

hi

thanks for your answer.

the crash of unity was not about the texture because i did’nt implemented it yet… that’s was just the threading

i will try to send the texture bytes via UDP, maybe it will be faster. I can scale down the video too, something like 200*200.

Is there any existant Unity script to encode the texture data?

Ok I have some new stuff …

I found the EncodeToPNG method (from Texture2D class). It returns me a byteArray, which can be sent through the network.

In the other side, I use the Texture2D.LoadImage to load this byteArray. It works perfectly on local: today I will try to send it using TCP Socket today.

I plan to send it using UDP (and maybe Broadcast, because I will have to send the texture to 10 computers). As the UDP mode is not connected, I’m not sure about receiving a frame from the begening, is there a way to know where is the start/end of the byteArray texture ?

Hey guys,

I’ve also discovered the PNG file functions in Unity. I’m pretty new to Unity and Unity networking. How did you send the texture over the net? The only met methods I know in Unity are synchronization (which doesn’t help here) or RPCs. I was thinking you could encode the image as a string and pass it that way. Do RPC functions take arrays of bytes? Any help in sending the texture data over the net would be greatly appreciated!

Thanks.

you can not use unity networking to send it, you must use .net sockets

Ok,

So I have to establish the connection and send all of the data through .net sockets in a script attached to whatever I want to send the image?

And if I’m sending an image here and there (not all the time), do you think it’s best to make the connection on startup and maintain it throughout or make the connection everytime I want to send the image and disconnect once the image has finished sending?