示例#1
0
    /** Initializes the member variables, and starts the thread. */
    public bool Initialize(string ipAddress, int port)
    {
        if (m_threadHandler != null)
        {
            UnityEngine.Debug.LogError("The TPSharedInfo instance has already been initialized.");
            return(false);
        }
        // Set up and start the message receiving thread.
        m_recvThread = new TPRecvThread();
        if (!m_recvThread.Initialize(ipAddress, port))
        {
            m_recvThread.Terminate();
            m_recvThread = null;
            return(false);
        }
        try {
            m_threadHandler = new Thread(new ThreadStart(m_recvThread.Run));
            m_threadHandler.Start();
        } catch (Exception e) {
            UnityEngine.Debug.LogError("Failed to start the message receiving thread : " + e.Message);
            m_threadHandler = null;
            return(false);
        }

        return(true);
    }
示例#2
0
    /** Stops the thread, and cleans up the member variables. */
    public void Terminate()
    {
        if (m_threadHandler == null)
        {
            return;
        }

        // Let the message receiving thread know that the user is trying to stop it.
        m_recvThread.Stop();
        // Wait the end of the thread.
        m_threadHandler.Join();

        m_recvThread.Terminate();
        m_recvThread    = null;
        m_threadHandler = null;
        m_ctrlEvents    = null;
    }