Search Unity

using System.Net for multiplayer? :D

Discussion in 'Multiplayer' started by ModLunar, Nov 16, 2019.

  1. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    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 :D
     
    Last edited: Nov 17, 2019
  2. dead_byte_dawn

    dead_byte_dawn

    Joined:
    May 7, 2015
    Posts:
    16
    Check out Colyseus.io it's a NodeJS based server that has a Unity SDK and there's pretty good documentation.
     
  3. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    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 :) . I appreciate you mentioning it though!
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    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.

    https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket?view=netframework-4.8
     
    Last edited: Nov 19, 2019
    ModLunar likes this.
  5. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    @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!
     
    Joe-Censored likes this.
  6. poettlr

    poettlr

    Joined:
    Mar 4, 2015
    Posts:
    17
    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 :)
     
    Joe-Censored likes this.
  7. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    @poettlr Ooh that's great to hear, thanks! :D

    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!
     
  8. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    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.
     
  9. qbvbsite

    qbvbsite

    Joined:
    Feb 19, 2013
    Posts:
    83
    ModLunar likes this.
  10. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    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.
     
  11. qbvbsite

    qbvbsite

    Joined:
    Feb 19, 2013
    Posts:
    83
    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.
     
    Last edited: Sep 9, 2021
  12. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    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!
     
  13. qbvbsite

    qbvbsite

    Joined:
    Feb 19, 2013
    Posts:
    83
    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.
     
    ModLunar likes this.