Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by ifdef_ben · Jun 15, 2017 at 10:24 PM · networkingnetworkserverapiconnection

Networking UNet: Why can we have multiple NetworkClient and how NetworkBehaviour knows which one to use?

Hi,

The title says it all but I'll elaborate. I'm learning to use the UNet network and some of parts the design of creating the connection between client and server confuse me.

You see, when you start a server in UNet you just use the static class NetworkServer and call Listen(). Everything is static so there is no ambiguity there.

But when you want to connect a client to a server you first have to create a new (non-static) NetworkClient object and then connect this NetworkClient instance to the server using Connect(). So:

  • Why do we have to instantiate a NetworkClient at all? This suggest that we might want to have multiple NetworkClient instances in the same game process. If so, what is the use of it (connecting to multiple servers?)?

  • If we really can have multiple connections how does this play with NetworkBehaviour synchronisation? How do NetworkBehaviours know on which connection to serialize to?

  • Since NetworkClients are instanciated do I need to keep a reference of their instance if I want to keep the connection? Otherwise my impression would be that the connection will be garbage-collected.

  • Regarding my previous question, I've found the NetworkClient.allClients array variable, a static array listing all NetworkClient instances. Would setting this variable to null then trigger a garbage-collect of the client connections?

I just can't get my head around why would a static class suffice for the Server but not for the Client.

For whoever takes the time to answer: Thank you very much! :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mazer83 · Jul 05, 2017 at 05:01 PM

Re: Multiple NetworkClients: Say you're making a turn-based game. You want to have online play, single-player and hot-seat (taking turns on the same device).

For the 1st option, you'll only need one client, (and a server if you're the host). For the 2nd and 3rd option, you're going to need multiple clients on the same process. You could just create a whole different set of classes for single-player and hot-seat play, but this way you don't have to, you can just re-use the architecture you used for online play, but just change the number of clients you spawn.

Re: Garbage collection. Yes, I believe you are correct.

Hopefully, someone can answer your 2nd bullet point question.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ifdef_ben · Jul 05, 2017 at 07:38 PM 0
Share

Thank you for taking the time to answer my question.

However, I think you are confusing clients and players. NetworkClients are only there to connect to the server and serves as a network Interface. They are not game objects so I'm not sure why you are talking about spawning them.

In your example I really don't see why you would need a *Network*Client in single-player and why would you want to connect 2 times on the same server in hot-seat. I get that design-wise this might appear simpler, but it just does not make sense network-wise. Also it really does not answer my main question which is "How NetworkBehaviour knows which NetworkClient to use if there are many?"..

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

106 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Is there a way to notify to the app once client has connected to server? 2 Answers

Why I cant use 2 NetworkManagers in the same time? 0 Answers

Unity Master Server Connect to own Server won't work 0 Answers

Unity Network make Server and Connect 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges