I’m working on a little project that I’d like to provide as a library to other Unity developers. It will communicate with a proprietary server over TCP/IP; that server will not be written in Unity (and probably not even in C#, for that matter). I’d like this library to be available to all Unity devs on all desktop and mobile platforms, without requiring Unity Pro. Bandwidth will be rather low, but latency needs to be kept low too.
What are my options for making that connection? Are System.Net and System.Net.Sockets available to all Unity devs? (I’ve read some conflicting info about these requiring Pro, or not working on iOS.) Are Unity’s networking classes appropriate for use with a non-Unity server? Any other options I should consider?
The socket APIs are not available on unity free for ios and android. I have built an UDP library which runs on all platforms of unity (as far as I know), https://github.com/fholm/udpkit
It’s for UDP obviously, but it might give you some ideas for how to do it.
Thanks Fredrik, that looks really interesting. It makes me wonder whether I should reconsider building my system on UDP (on top of your library) rather than TCP. I know UDP packet delivery is not guaranteed, but for my purposes that’s probably fine, especially if I can argue that you gain the benefit of lower latency. I had chosen TCP mainly because it’s what I’m most familiar with, but UDP might actually be better.
There’s no reason I would have to use your library for the server (rather than a UDP socket in any other environment), is there?
One final question: suppose I do decide to write the server in C#… I see your examples include what appear to be console apps, which I guess I could just compile with mono, and throw up on a Rackspace server. Are there any dragons lurking there, or would you expect that to just work?
My library requires it to be on both the server and the client, as it allows you to send packages with delivery notification over UDP (which in turns let you implement things like reliable, reliable ordered, etc.).
If you want to use my library it should just run on Mono yes.
You definately want UDP and particularly ‘unreliable’ when it comes to updating gameObjects that are going to be changing every frame.
Because if a packet goes missing it’s not the end of the world and the gameObject can just receive the next packet’s data, and the user will hardly notice that anything went missing.
If it was reliable, however, your gameObject would keep rejecting packets until the reliable packet was successfully received, and that could cause a huge lag spike or other undesired behaviour.
Good point. Yes, I think I’m convinced, and I’ve successfully shifted my mindset into UDP gear.
I’m going to give the udpkit library a try. It sounds like Fredrik has done an amazing job of handling common needs, achieving good performance, and doing it all in a way that works even on mobile and web, and even with the free version of Unity.