예제 #1
0
        /// <summary>
        /// Default timeout on a connection attempt it something around 15 seconds, which is ridiculously long.
        /// </summary>
        private void CancelConnect(object obj)
        {
            IAsyncResult result = (IAsyncResult)obj;

#if !UNITY_WINRT
            if (result != null && !result.AsyncWaitHandle.WaitOne(3000, true))
            {
                try
                {
                    Socket sock = (Socket)result.AsyncState;

                    if (sock != null)
                    {
                        sock.Close();

                        lock (connectingList)
                        {
                            // Last active connection attempt
                            if (connectingList.size > 0 && connectingList[connectingList.size - 1] == sock)
                            {
                                socket = null;

                                if (!ConnectToFallback())
                                {
                                    Debug.LogError("[Client][TcpProtocol:ConnectToFallback()] -> Unable to connect");
                                    Error("Unable to connect");
                                    Close(false);
                                }
                            }

                            connectingList.Remove(sock);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            }
#endif
        }
예제 #2
0
        /// <summary>
        /// Remove the specified player.
        /// </summary>
        private void RemoveClient(TcpProtocol client)
        {
            if (client != null)
            {
                client.Release();
                clients.Remove(client);

                if (client.Id != 0)
                {
                    if (clientsDictionary.Remove(client.Id))
                    {
                    }

                    client.Id = 0;
                }
            }
        }