Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Unity transport layer maximum connections

Discussion in 'Unity Transport' started by Wolk, Aug 10, 2017.

  1. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    Hello, I'm writing a simple mmo, and i quite like the serialization on the unities transport layer, plus it allows me to do game logic. However, can someone tell me what's the max connections i can have, it's not defined anywhere
    "
    The final step of network configuration is topology definition. Network topology defines how many connections allowed and what connection configuration will used:

    HostTopology topology = new HostTopology(config, 10);

    "


    I'm also concerned about performance, since unity is single threaded i'm quite sure i won't be able to handle many connections at all. What would be a good suggestion for a simple mmo server.
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Well. Change the max connections on your host topology?. And you can multithread your server if you want. Aslong as you recieve from the main thread
     
  3. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    Afaik, unities corroutines aren't multi threaded, i'd have to use C#'s multi threading i guess.

    As i said, the maximum number of connections is 65k, which is the number of 16bit ip's. Meaning i can't have two connections from the same ip? Either way, i'd like to have more than 65k people connected...
     
  4. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Coroutines are not threads. But as I said. If you multithread the app. You can probably hold alot more.


    and why would you not be able to have more than 65k players? Unet,s limit is over 2 mil. (Int max size)
     
  5. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    ArgumentOutOfRangeException: Number of connections should be < 65535
    Parameter name: maxDefaultConnections
    UnityEngine.Networking.HostTopology..ctor (UnityEngine.Networking.ConnectionConfig defaultConfig, Int32 maxDefaultConnections) (at C:/buildslave/unity/build/Runtime/Networking/Managed/NetworkTransportConfig.cs:487)
    Server.Start () (at Assets/Server.cs:13)
     
  6. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    http://answers.unity3d.com/questions/1141138/unity-networking-transport-layer-max-connection-li.html Might help you.
     
  7. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    Saw that thread already, but i don't think it's answered there on how to do it. How do i add another connection based on the same ip (i guess different port)?
     
  8. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    The comments on the accepted answer explains how to go about it.
     
  9. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Actually, this is not correct. Infact, 65535 seems to be the limit for Unet.
    Quote from Alex:
    ">Connection descriptor is an int? Why limit yourself to only 2,147,483,647 connections?
    :)
    inside connection described as uint16_t ~65535 connection… We decided to leave int in C# API for the reason do not bore people with casting. If you will over limit this value you will receive error."
     
  10. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    Not quite sure that comment got it to work. Yeah, that's the problem, i need to figure out how to make a different "connection" for a different person behind the same ip i believe
     
  11. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Why do you need so many people on one server? Do you need that many realtime connections at once?
     
  12. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    More than 60k for sure.
    Yes, they won't take much bandwidth or cpu power, but it'd be a hassle to authenticate them each time they make a move, so i won't be opening and closing so many connections as well.
     
  13. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    If it's not a realtime game. I don't think UDP sockets is the way to go. And all you would have to do is to supply a token or something to the game server.
     
  14. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    int myReiliableChannelId = config.AddChannel(QosType.Reliable);
    It's using tcp, not utp.
    I can't really assign tokens,
    NetworkTransport.AddHost(topology,port,extra_ip); I would have to know how to add a connection depending on a different client and no one has managed to explain that so far..
     
  15. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    No. UNET is udp only.
     
  16. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    Each message is guaranteed to be delivered but not guaranteed to be in order.

    I guess you're right, but it doesn't really make a difference imho. I'm just concerned about the max connection size
     
  17. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Well, if you need more than 60k players on one connection. I think you will face more design issues and that the connection limit is the least of your problems. Let alone atracting that amount of players. Currently the number 10 game on steam has 45k players playing it. And GrantTheftAuto 5 currently has 55k. I don't see why you don't offload to multiple servers.
     
  18. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59

    True, but it's a simple game really, not much data to be processed at all. I guess i'll write architecture to distribute the load, but again i would like to at least theoretically solve the issue of the nr. of connections
     
  19. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    If you are only using reliable communication and not alot of data. Go for TCP IP. And if you are planning to beat GrandTheftAutos player count. Well, I guess just use more than ONE server? That poor server will have a lot to do managing 60k connections.
     
  20. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59

    True, but it's a simple game really, not much data to be processed at all. I guess i'll write architecture to distribute the load, but again i would like to at least theoretically solve the issue of the nr. of connections
    The problem is that the transport layer offers some nice serialization and has a nice interface, kinda not sure if i should go for C#'s tcp
     
  21. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    The Transport Layer offers no serialization. Just pure Byte[] sending. If you are talking about the NetworkWriter & Reader. (HLAPI), there is similar things in the .NET library. Look at BinaryWriter and BinaryReader
     
  22. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    Yep, i was actually thinking of BinaryFormatter and then sending those bytes. Well, i'll give the unet a try, and if it turns out bad i can always rewrite it quickly if i make a modular architecture :)
    Still, it would be nice if someone knew how to increase the number of connections on the unet topology.

    I'll also use "cookies" or some similar token for staying connected. The problem i have is actually syncing the game, meaning i have to do O(n) writes where n is the number of connected people to sync with
     
  23. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Then do a multicast?