UNET - How to abort asynchronous call NetworkClient.Connect()?
Hi,
is there a way to abort the asynchronous task of NetworkClient.Connect()
? I tried NetworkClient.Disconnect()
, however this has no effect during the process of connecting.
My Scenario: I need this because I set my NetworkServer to allow only one connection at a time and when a second client connects, the server refuses the client. However, the client is not being informed about this and tries a long time to connect before timing out. There is no MsgType.ServerFull
or something similar which triggers in such a case (or did I miss?). So my solution is to listen asynchronously for client.IsConnected()
to become true and if it doesn't within my own specified timeout, the connection attempt shall be canceled.
Cheers, phineliner
Answer by phineliner · Nov 11, 2015 at 04:28 PM
Found a workaround:
You can call client.ShutDown()
, which will invalidate the client. But it also seems to abort the client.Connect()
task, which is what I wanted. Note: you will have to reinitialize the client object if you want to continue using it.
Hope this helps someone else.
Cheers, phineliner
hello, how I need to attach it, call client.ShutDown() on server?
Hi. No you call it on the same client from where you initiate the connect-request.
Your answer
Follow this Question
Related Questions
Unity Networking, where do I start? 0 Answers
UNET - How to wait for NetworkConnection.Send(...) to finish? 0 Answers
Networking concept and spawning questions 1 Answer
Why do I need [Command] for NetworkServer.Spawn() , but not for NetworkServer.Destroy()? 0 Answers
get receive from socket wifi 0 Answers