Search Unity

Resolved Connecting to more than one server

Discussion in 'Netcode for GameObjects' started by rainboww, Feb 7, 2023.

  1. rainboww

    rainboww

    Joined:
    Jan 5, 2017
    Posts:
    125
    Hello Community,
    My Project is a decentralized messenger without dedicated server instead i have a host to host approach where every app can receive connections or send connections as required.
    Generally writing the app is working well with unity and much of the core architecture stands but there are some limitations especially in networking.

    I found that Netcode seems to only support one Network Manager and thus only one connection as client, i was not able to find more on the documentation but i got an error when adding more than one NetworkManager: Failed to spawn NetworkObject for Hash 1612385727.
    Now i want to connect from one App to different Hosts.

    You can think it like this:

    You have one friend you want to chat with, he is online so he is automatically working as host and receives incoming messages. So you connect to him as Client and execute Send Message as RPC.

    So the essential Question is: How do i connect as Host to multiple other Hosts in a manner RPCs can be executed without an error related to the required Network Object?
     
    Last edited: Feb 7, 2023
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @rainboww , you can only have 1 NetworkManager. NGO is not meant to use a full p2p model: there always has to be a server, and you can connect to one of them. It's not the tool you want to use for your use case, unless you want to create a chat server to which everybody else connects (ther are better services to do this and they don't involve NGO)
     
  3. rainboww

    rainboww

    Joined:
    Jan 5, 2017
    Posts:
    125
    Hello @RikuTheFuffs-U
    I have tried external tools. but found them lacking.
    So i want to have a unity supported tool.
    What would you recommend for my case?
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,989
    You can go low-level and implement this using any UDP socket library since you don't need connection state to send strings with some metadata (ie user id/name, chat channel, etc) across networks to some other IP and port. Though of course you'll be running into issues where the destination is unreachable due to firewalls or port forwarding not established. Hence chat services usually route traffic through their own servers and want you to pay for that service.

    As to lacking: lacking what specifically? And what makes you think a Unity supported tool would not be lacking the features you're seeking? ;)
     
  5. rainboww

    rainboww

    Joined:
    Jan 5, 2017
    Posts:
    125
    Thats ofcourse a question of expectation say trying to play a video from a byte array or stream and finding out that unity only plays it from harddisk with no workaround gives the feeling something is lacking or the network stuff which is also only programmed so it can only be used in a narrow purpose. So its the question how much to expect at all.

    Any UDP socket library sounds like maybe an approach i must admit for many things i avoid too high level stuff since often it does in the end not exactly what i want - its usually outside of the box.

    However it is not exactly a super simple chat app where you send only text but other stuff too like files or settings.
     
    Last edited: Feb 8, 2023
  6. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    441
    If you're going to go with a low-level approach and want to use a Unity-supported solution, you could look into the Unity Transport package (documentation for the 2.0 version might be more complete and easier to follow). It's what is used by default by NGO under the hood.

    While it is also based on a client-server model, unlike NGO, it doesn't have any limitations around how many instances can be used at the same time. So you could simply have multiple
    NetworkDriver
    instances to implement some kind of P2P topology. Doing so might not scale to hundreds of peers, however. Note also that it's designed to be used as a solution for multiplayer games, and so optimizes for this use case (e.g. frequent and relatively small messages). It might not be ideal if you're frequently sending large blobs of data (like files).
     
  7. rainboww

    rainboww

    Joined:
    Jan 5, 2017
    Posts:
    125
    In the end i decided to do it with system included tcp, i wrote most of the dowload manager already looks like it will work for me.
    Thankyou for the help.