Beispiel #1
0
 /// <summary>
 /// Освобождение ресурсов
 /// </summary>
 /// <param name="disposing"></param>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposeEvents();
         DisposeSocket();
         if (poolEventArgs != null)
         {
             poolEventArgs.Dispose();
             poolEventArgs = null;
         }
     }
     base.Dispose(disposing);
 }
Beispiel #2
0
        /// <summary>
        /// Создание сокета по указанному IP адресу и порту
        /// </summary>
        /// <param name="server">IP адрес</param>
        /// <param name="port">Порт</param>
        /// <returns>True - в случае успеха</returns>
        protected bool CreateSocket(string server, int port)
        {
            exceptionThrown = false;
            string _server = string.IsNullOrEmpty(server) || server == "." ? "localhost" : server;

            if (!CreateIPEndPoint(_server, port))
            {
                return(false);
            }

            try
            {
                socket        = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                poolEventArgs = CreatePoolSocketAsyncEventArgs();
            }
            catch (System.Exception ex)
            {
                SetException(ex);
                return(false);
            }
            return(true);
        }