Esempio n. 1
0
        /**
         * @brief 关闭当前 socket
         */
        public void closeCurSocket()
        {
            if (m_curClient != null)
            {
                string ip;
                int    port;

                ip   = m_curClient.m_ip;
                port = m_curClient.m_port;

                string key = ip + "&" + port;

                // 关闭 socket 之前要等待所有的数据都发送完成
                //m_id2SocketDic[key].msgSendEndEvent.Reset();        // 重置信号
                //m_id2SocketDic[key].msgSendEndEvent.WaitOne();      // 阻塞等待数据全部发送完成

                if (m_id2ClientDic.ContainsKey(key))
                {
                    #if NET_MULTHREAD
                    using (MLock mlock = new MLock(m_visitMutex))
                    #endif
                    {
                        m_id2ClientDic[key].Disconnect(0);
                        m_id2ClientDic.Remove(key);
                    }
                    m_curClient = null;
                }
            }
        }
Esempio n. 2
0
        /**
         * @brief 关闭 socket
         */
        public void closeSocket(string ip, int port)
        {
            string key = ip + "&" + port;
            if (m_id2ClientDic.ContainsKey(key))
            {
                // 关闭 socket 之前要等待所有的数据都发送完成,如果发送一直超时,可能就卡在这很长时间
                #if NET_MULTHREAD
                m_id2ClientDic[key].msgSendEndEvent.Reset();        // 重置信号
                m_id2ClientDic[key].msgSendEndEvent.WaitOne();      // 阻塞等待数据全部发送完成
                #endif

                #if NET_MULTHREAD
                using (MLock mlock = new MLock(m_visitMutex))
                #endif
                {
                    m_id2ClientDic[key].Disconnect(0);
                    m_id2ClientDic.Remove(key);
                }
                m_curClient = null;
            }
        }
Esempio n. 3
0
        /**
         *@brief 打开到 socket 的连接
         */
        public bool openSocket(string ip, int port)
        {
            string key = ip + "&" + port;
            if (!m_id2ClientDic.ContainsKey(key))
            {
                m_curClient = new NetTCPClient(ip, port);
                m_curClient.Connect(ip, port);
                #if NET_MULTHREAD
                using (MLock mlock = new MLock(m_visitMutex))
                #endif
                {
                    m_id2ClientDic.Add(key, m_curClient);
                }
            }
            else
            {
                return false;
            }

            return true;
        }
Esempio n. 4
0
        /**
         * @brief 关闭 socket
         */
        public void closeSocket(string ip, int port)
        {
            string key = ip + "&" + port;

            if (m_id2ClientDic.ContainsKey(key))
            {
                // 关闭 socket 之前要等待所有的数据都发送完成,如果发送一直超时,可能就卡在这很长时间
                #if NET_MULTHREAD
                m_id2ClientDic[key].msgSendEndEvent.Reset();        // 重置信号
                m_id2ClientDic[key].msgSendEndEvent.WaitOne();      // 阻塞等待数据全部发送完成
                #endif

                #if NET_MULTHREAD
                using (MLock mlock = new MLock(m_visitMutex))
                #endif
                {
                    m_id2ClientDic[key].Disconnect(0);
                    m_id2ClientDic.Remove(key);
                }
                m_curClient = null;
            }
        }
Esempio n. 5
0
        /**
         *@brief 打开到 socket 的连接
         */
        public bool openSocket(string ip, int port)
        {
            string key = ip + "&" + port;

            if (!m_id2ClientDic.ContainsKey(key))
            {
                m_curClient = new NetTCPClient(ip, port);
                m_curClient.Connect(ip, port);
                #if NET_MULTHREAD
                using (MLock mlock = new MLock(m_visitMutex))
                #endif
                {
                    m_id2ClientDic.Add(key, m_curClient);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        /**
         * @brief 关闭当前 socket
         */
        public void closeCurSocket()
        {
            if(m_curClient != null)
            {
                string ip;
                int port;

                ip = m_curClient.m_ip;
                port = m_curClient.m_port;

                string key = ip + "&" + port;

                // 关闭 socket 之前要等待所有的数据都发送完成
                //m_id2SocketDic[key].msgSendEndEvent.Reset();        // 重置信号
                //m_id2SocketDic[key].msgSendEndEvent.WaitOne();      // 阻塞等待数据全部发送完成

                if (m_id2ClientDic.ContainsKey(key))
                {
                    #if NET_MULTHREAD
                    using (MLock mlock = new MLock(m_visitMutex))
                    #endif
                    {
                        m_id2ClientDic[key].Disconnect(0);
                        m_id2ClientDic.Remove(key);
                    }
                    m_curClient = null;
                }
            }
        }