using System.Net for multiplayer? :D

My main question is: does the System.Net namespace/API work well with Unity? I know it does not work on WebGL because of a limitation with sockets in the browser. Does it work well on other platforms? (Mostly concerned about Windows/Mac/Linux computers, and consoles including PS4, Xbox One, and Switch)

I am wondering because with some DLLs/APIs, it can be hard to make it work with Unity sometimes due to .NET Framework versions, NuGet packages getting auto-deleted by Unity’s auto-generation of the Visual Studio solution, etc. (The good thing though is that recently with .NET 4.x support, this is becoming less of an issue)

Extra background info:
I’d like to make multiplayer games someday (not yet), and am thinking about what library to use in C# to help with networking code. I know it will be a learning curve and I will need to consider writing my own stuff on top of it, but I don’t mind that too much. I’d like to invest a fairly large amount of time towards getting good with one library for this, so I can become comfortable with it and make good use of it for a long time. I just don’t wnat to commit the time to a given API if it has a groundbreaking limitation between itself (System.Net in this case) and Unity!

Thanks for the help as always :smile:

Check out Colyseus.io it’s a NodeJS based server that has a Unity SDK and there’s pretty good documentation.

Ahh, interesting. I checked out their website and it looks pretty convenient! Though I am still wondering about System.Net, since I’d like to learn about it for educational purposes first at least :slight_smile: . I appreciate you mentioning it though!

System.Net.Sockets.Socket is the go to class for writing your own network API for a networked game, and is arguably the core functionality of the System.Net namespace. It is often referred to simply as the “Socket class”, which is how you’ll typically see it mentioned on this forum and many other programming forums.

Writing a network API using the Socket class will of course use other stuff under System.Net. Note that Sockets gives you access to networking at a pretty low level, so you’ll typically need to create your own higher levels of abstraction when creating your own network API before you have something usable in your game, unless your game is extremely simple.

For example, when using a UDP Socket you’ll be dealing with sending/receiving individual unreliable byte arrays. On top of that you build your higher level systems, such as serializing classes which have meaning to your game, features such as reliability or message fragmentation, etc.

1 Like

@Joe-Censored Ooh, that’s what I needed to hear: to make sure it’s the right core/base functionality I should use to build on top of. Thanks so much!

1 Like

I can’t get into too many details (NDA and such), but we use System.Net on PC, PS4 and Nintendo Switch and have not run into any problems as of yet. Though depending on what you do you might have to move closer to the system and write your own native c/cpp plugin for each platform.

I hope that at least helps you picking a usable library to depend on :slight_smile:

1 Like

@poettlr Ooh that’s great to hear, thanks! :smile:

I’m not well-versed in C++ yet as I am with C#, so I hope I don’t have to do that (native C/C++ plugin per platform). But if it comes down to it, cross-platform play is extremely important for me, so I’d say to heck with it and do it anyway! XD

Thanks again for the info!

I reccomend Toms Networking solution.
Is server based, includes TCP and UDP data and is very easy to work with once you understand how it works.

I’m doing this, you can check our my blog here: Creating an Isometric 2D RPG/MMO (Ongoing Series)

I use LiteNetLib as my network layer but can be swapped out at any time.

1 Like

That’s awesome, thanks a lot for sharing!
We used LiteNetLib at my last fulltime job for an MMO, and I started learning about it recently and joined their discord channel!

I’m working on a 2D MMORPG currently, and plan to replace my current networking to use it under the hood, which would be a significant performance improvement.

Awesome man, feel free to PM any questions you may have. Also would like to check our your 2D RPG if you have anything to show atm.

Aw thanks! Yeah sure, I should really get up on it.
I need to decide on a plan for the next 2-3 years with it, given that I need to maintain my fulltime software engineer job.

It’d be cool to release dev logs about it regularly, share info about it on the forums, and stuff like that.
I think I’m nervous still cause there’s so much work to be done haha.

I’ll let you know if/when I do!

Sounds good man, ya having a full time job and making a game solo is pretty difficult for sure. I have started/reworked things over that past 10 years learning new things every time. One reason I started that post was to keep the project going forward hopefully it works and I have something to show in a years time lol.

1 Like