public bool NewConnect(string sockInfo, string strIp, int nPort) { bool bRes = false; if (null == sockInfo) { return(bRes); } TcpSocketAny any = new TcpSocketAny(); any.Connect(strIp, nPort); while (!any.isConnected) { } ; if (!Sock_List.ContainsKey(sockInfo)) { Sock_List.Add(sockInfo, any); ThreadPool.QueueUserWorkItem(RecvFunc, sockInfo);//启动接受检测线程 bRes = true; } return(bRes); }
public bool IsConnected(string sockInfo) { bool bRes = false; TcpSocketAny any = null; Sock_List.TryGetValue(sockInfo, out any); if (null != any) { bRes = any.isConnected; } return(bRes); }
private static void SendFunc(object obj) { Sendinfo send = (Sendinfo)obj; if (null != send.manager && null != send.arr && 0 != send.nBytes) { TcpSocketAny any = null; send.manager.Sock_List.TryGetValue(send.sockinfo, out any); if (null != any) { any.Send(send.arr, send.nBytes); } } }
public void CloseConnect(string sockInfo) { if (Sock_List.ContainsKey(sockInfo)) { TcpSocketAny any = null; Sock_List.TryGetValue(sockInfo, out any); if (null != any) { any.Close(); } Sock_List.Remove(sockInfo); } }