Beispiel #1
0
        protected void OnDisconnect(object sender, EventArgs args)
        {
            NetworkConnector connector = sender as NetworkConnector;

            //connector.Tag=null;
            connector.Dispose();
        }
Beispiel #2
0
        public void acceptCallback(IAsyncResult ar)
        {
            //log.Info("Accepting connection");

            Socket listener = (Socket)ar.AsyncState;
            Socket client   = null;

            try
            {
                client = listener.EndAccept(ar);
            } catch (Exception ex)
            {
                Console.WriteLine("Exception in accept: {0}", ex);
                throw;
            }
            client.NoDelay = true;
            allDone.Set();

            // Additional code to read data goes here.
            NetworkConnector connector = new NetworkConnector(client);

            connector.Disconnected += OnDisconnect;

            //this line for save reference to connector in .NET
            //and prevent to collecting it by GC
            //uncomment it to produce socket leaks
            //connectors.Add (connector);

            connector.Receive();
        }