Search Unity

What should I use in 2020 to setup local wireless multiplayer?

Discussion in 'Scripting' started by Lethn, Jan 27, 2020.

  1. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    I've been having a think and one thing I thought would be really nice to do which wouldn't require me setting up online multiplayer would be to get some kind of local multiplayer going over wireless ( Or wired ) internet. What I'm looking for is to let any computer that's connected to a network setup over LAN and connect to a game.

    Does anyone know how I would do that in 2020? I know a lot of multiplayer stuff is deprecated but surely because it's all local I should be able to get that setup even now right?
     
    Last edited: Jan 27, 2020
  2. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    If you're asking about a more 'complete' solution which takes care of a lot of stuff for you, I'm not aware of any, but I also didn't have to look for one because what I had was enough for my use case. So maybe someone else can help with that.
    But if you're just looking into discovering potential servers in the network, I have an approach that I've used before. It's pretty rudimentary:
    - establish a port your game will run on, or 2, or 3 ports (as a fallback)
    - start the server on any device
    - when players press "join" on other devices, find your local ip. Say it's 192.168.100.4. Then simply for i in 0 to 255, check if there's a server listening at 192.168.100.i at one of the established ports. This way you can collect a list of the available LAN servers.
    It can be optimized, but this is the general idea.
     
  3. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Do you know of any documentation or tutorials that demonstrate how this is all done? That's the main thing for me and then I can experiment, I'm not looking for online right now, just how to do it over LAN.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    Just start from something basics as UDP.
    That will start get you going.
    You can look also into sockets.
     
    Joe-Censored likes this.
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
  6. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    I'm currently using SuperSocket.WebSocket in the server-side and WebSocket4Net for client-side (you'll use both on the same device, since your devices can act as both the server and the client). I chose WebSocket protocol because at the time it was the only way to have networking in WebGL. Don't know if that changed meanwhile.
    This solution works great because you can send/receive raw bytes so you have full control over the data. It took me about 1 week to master it, but now I'm using it in a pretty complex turn-based multiplayer board game (in development) and it's a long-term solution IMO.

    You also need to take care about endianness (byte order for ints, longs differ on different devices). For example when appending ints to a message (which is byte array here, Data):
    ByteArrayBuilder
    Code (CSharp):
    1.  
    2.         public void AppendInt(int value)
    3.         {
    4.             value = IPAddress.HostToNetworkOrder(value);
    5.             AppendBytes(BitConverter.GetBytes(value));
    6.         }
    ByteArrayParser
    Code (CSharp):
    1.         public int ReadNextInt()
    2.         {
    3.             var value = BitConverter.ToInt32(Data, ReadOffset);
    4.             value = IPAddress.NetworkToHostOrder(value);
    5.             ReadOffset += sizeof(int);
    6.  
    7.             return value;
    8.         }
     
  7. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    I'll have a look at forge networking again, it seems they've updated it since I last looked and even added proper documentation which is great, going to have to research it though.

    Edit: Ehhh, kinda meh on forge networking still.
     
    Last edited: Jan 27, 2020
  8. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    I need something a noob to networking can learn, ideally I guess I'm hoping for some up to date tutorials. I just need something I can work through that doesn't blatantly have explanations missing or even worse barely existent documentation.

    Gah it's frustrating reading anything to do with Unity multiplayer.
     
    Last edited: Jan 27, 2020
  9. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Ah, well, sorry I couldn't be of help. We're using Forge right now and it's working great for us. Though I am always interested in what others are using.
     
  10. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    My best option is probably to write a begging letter and get early access to connected games :( lol there seems to be nothing particularly reliable out there for networking noobs like me.
     
  11. robto

    robto

    Joined:
    Aug 6, 2015
    Posts:
    9
  12. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    I ended up using PUN 2 again and working through it, this time I managed to get through things by finding some up to date PUN 2 tutorials.
     
  13. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    Why is this suddenly almost impossible to implement a simple solution for local (LAN) multiplayer? :(

    Is there even ways to do that right now?
     
  14. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    I don't know but if you find anything I'd like to see it.
     
  15. amxxvi

    amxxvi

    Joined:
    Dec 23, 2017
    Posts:
    12
    If you still remember them, would you provide the links to those up-to-date PUN 2 tutorials here?
     
  16. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    It depends on what you're looking for help with but this one seemed to work alright for me, I was mainly stuck on synchronising text but once I got that sorted everything else was fine.