/** * @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; } } }
/** * @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; } }
/** *@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; }
/** *@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); }
/** * @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; } } }