Exemplo n.º 1
0
        public Connection(OnConnectionConnect onConnected       = null,
                          OnConnectionDisconnect onDisconnected = null,
                          OnConnectionError onError             = null,
                          OnConnectionRecv onRecv = null)
        {
            m_OnConnectionConnect    = onConnected;
            m_OnConnectionDisconnect = onDisconnected;
            m_OnConnectionError      = onError;
            m_OnConnectionRecv       = onRecv;

            m_MessageQueue = new Queue();
            m_Mutex        = new object();
        }
Exemplo n.º 2
0
        public void Disconnect(bool reuse = false)
        {
            m_OnConnectionConnect    = null;
            m_OnConnectionDisconnect = null;
            m_OnConnectionError      = null;
            m_OnConnectionRecv       = null;

            if (m_Socket?.Connected == true)
            {
                try {
                    m_Socket.BeginDisconnect(reuse, OnDisconnected, null);
                } catch (SocketException) {}
            }

            if (!reuse)
            {
                m_Socket.Dispose();
                m_Socket = null;
            }
        }