Exemplo n.º 1
0
 public void Dispose()
 {
     m_bufferManager.Dispose();
     m_bufferManager = null;
     m_readWritePool.Dispose();
     m_readWritePool = null;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 初始化客户端
        /// </summary>
        /// <param name="hostName">服务端地址{IP地址}</param>
        /// <param name="port">端口号</param>
        public SocketClient(string hostName, int port)
        {
            IPHostEntry host = Dns.GetHostEntry(hostName);

            IPAddress[] addressList = host.AddressList;
            this.hostEndPoint    = new IPEndPoint(addressList[addressList.Length - 1], port);
            this.clientSocket    = new Socket(this.hostEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            this.m_bufferManager = new SocketBufferManager(32768, 32768);
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     m_bufferManager.Dispose();
     m_bufferManager = null;
     autoConnectEvent.Close();
     if (this.clientSocket.Connected)
     {
         this.clientSocket.Close();
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 初始化服务器端
 /// </summary>
 /// <param name="numConcurrence">并发的连接数量(1000以上)</param>
 /// <param name="receiveBufferSize">每一个收发缓冲区的大小(32768)</param>
 public SocketListener(int numConcurrence, int receiveBufferSize, GetIDByIPHandler GetIDByIP)
 {
     this.m_serverState              = ServerState.Initialing;
     this.m_numConnections           = 0;
     this.m_numConcurrence           = numConcurrence;
     this.m_bufferManager            = new SocketBufferManager(receiveBufferSize * numConcurrence * m_opsToPreAlloc, receiveBufferSize);
     this.m_readWritePool            = new SocketAsyncEventArgsPool(numConcurrence);
     this.m_semaphoreAcceptedClients = new Semaphore(numConcurrence, numConcurrence);
     if (GetIDByIP != null)
     {
         this.GetIDByIP = GetIDByIP;
     }
     else
     {
         this.GetIDByIP = (ip) => { return(_ipID[ip]); }
     };
 }