Search Unity

Dedicated server + Peer-to-peer

Discussion in 'Multiplayer' started by jdcart23, Aug 31, 2018.

  1. jdcart23

    jdcart23

    Joined:
    Jan 17, 2018
    Posts:
    12
    We've been using the HLAPI for our project for a while now and we haven't had any major problems.

    Currently we have a dedicated server and multiple machines that connect to it, however, now we also have the need of connecting and sending messages client-to-client. Unless I'm missing something, currently, the only way to do this would be to send the messages from one client, and route all these messages through the server to ultimately reach the receiving client, e.g.:

    Client1: CmdSendMessage() ---> Server: TargetRpcSendMessage() ---> Client2: ReceiveTargetRpc().

    This is not something that we would like to do because of the added latency of going through the server for every message. These messages will be really small (1 vector, 1 quaternion per frame).

    Since the HLAPI is just a layer above the LLAPI, I was wondering if I can just open a new connection on the clients through the LLAPI where they can communicate directly. So far I haven't been successful on doing this.

    Has anybody tried this before, is it possible?

    The other alternative that I have is using .Net sockets or another library to achieve what I need, however, if I can do everything directly with what Unity provides I'd prefer to do that.
     
  2. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Each client _could_ be a server, and everyone could connect to everyone else, mesh-like. Don't do it. Eat the lag involved in Client -> Server -> Client. Or prepare for some kind of difficulties in QA and real-world use. YMMV, IMHO, etc etc.

    Good Luck!
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Your biggest problem will be computers on the Internet are usually behind a NAT enabled router. You'd need every client to set up port forwarding on their router, which I'd think would be an unreasonable assumption. Mobile devices on cellular networks often have the same issue, but the user doesn't even have access to the router to make that kind of change.

    Creating a mesh network using NAT punch through is not impossible as an alternative, but don't expect it to be reliable. Most likely at least one of your game's punch through connections would fail and just piss off everyone when the game consistently has connection issues.
     
  4. jdcart23

    jdcart23

    Joined:
    Jan 17, 2018
    Posts:
    12
    To elaborate a little more on the problem. Our application will always run on a LAN where we have control over our own router/network, however, we prefer to have a setup that doesn’t involve any crazy router configuration in order for it to work, considering other people will be troubleshooting this on their own.

    In the past, in an old version of our application and for solving this same problem, we were using HLAPI + Raknet for client-to-client communication and it worked fine. Unfortunately, we decided not to use Raknet for our current application. We are basically looking to replace Raknet.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You should be able to use the LLAPI or NetworkServerSimple for these extra connections then.