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
1
Question by jeango · Nov 03, 2016 at 02:41 PM · networkingcallback

UNet: How to know when a client fails to connect

Hi, I'm trying to make a custom GUI for the login scene for a game that uses the Networking API

One thing I'm trying to achieve is to display a "Connecting" message when I call StartClient() and if the connection attempt times out, I want to display a "Could not connect to the server" message.

But I have no idea how to do this. I see there are a lot of callbacks available, but I tried OnClientError, OnServerError, OnClientDisconnect, OnClientNotReady but apparently none of these callbacks are called here.

I'm pretty sure this should be possible because the NetworkManager's default HUD does something like that, but I have no idea how, and the documentation is no help.

edit: here is the code of my NetworkManager

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 
 public class CustomNetworkManager : NetworkManager {
     
     void OnClientError(NetworkConnection conn, int errorCode) {
         print ("ClientError");
         print (conn);
         print (errorCode);
     }
     void OnStopClient() {
         print ("StopClient");
     }
     void OnClientDisconnect(NetworkConnection conn) {
         print ("ClientDisconnect");
         print (conn);
     }
     void OnClientNotReady(NetworkConnection conn) {
         print ("ClientNotReady");
         print (conn);
     }
 }
 

edit 2: I also tried to get the NetworkClient when I call StartClient and to register a handler for the Error MsgType... to no avail

     public void StartClient() {
         SetServerIp ();
         NetworkClient client = NetworkManager.singleton.StartClient ();
         client.RegisterHandler (MsgType.Error, ConnectionError);
 
     }
 
     public void ConnectionError(NetworkMessage netMsg) {
         print ("connection error");
         print (netMsg);
     }


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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by kroth · Nov 03, 2016 at 07:27 PM

Register a handler for the message type MsgType.Disconnect. This is the message handler called when the client fails to connect to a server.

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 jeango · Nov 03, 2016 at 10:15 PM 0
Share

Thanks a lot, this worked like a charm.

so the solution is as follows

 client.RegisterHandler ($$anonymous$$sgType.Disconnect, ConnectionError);


avatar image
0

Answer by Cynikal · Nov 03, 2016 at 03:07 PM

     void OnFailedToConnect(NetworkConnectionError error) {
         Debug.Log("Could not connect to server: " + error);
     }
Comment
Add comment · Show 3 · 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 jeango · Nov 03, 2016 at 03:16 PM 0
Share

hm... searching in the doc, this is part of the Network class. So how can I hook into this callback from my Network$$anonymous$$anager? I don't even know how to get a reference to the Network

avatar image jeango jeango · Nov 03, 2016 at 03:20 PM 0
Share

Actually it looks like the Network class is not even part of the Networking namespace, so I believe it's not part of the Networking API (unless I'm misunderstanding something)

avatar image SweatyChair · Apr 18, 2019 at 08:13 AM 0
Share

I think this is for the old $$anonymous$$asterServer...

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

81 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

Related Questions

Where should I override the Network Manager Callbacks? 0 Answers

Why not using Start exlusively in NetworkBehaviours? 0 Answers

Unity networking tutorial? 6 Answers

Unity TCP async functions 0 Answers

Cmd on a runtime created object 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