Beispiel #1
0
        private void OnClientConnect(IAsyncResult asyn)
        {
            try
            {
                if (!_isListening)
                {
                    return;
                }
                Socket socket = _listener.EndAccept(asyn);
                if (socket == null)
                {
                    return;
                }

                int           id     = SocketHelper.GetNewSocketID();
                ISocketWorker worker = SocketWorkerFactory.Create(id, socket, this);
                if (worker == null)
                {
                    SocketLogMgt.SetLog(SocketLogType.Error, this, "Create socket worker failed.");
                    return;
                }

                worker.Open();

                //_listener.BeginAccept(new AsyncCallback(OnClientConnect), null);
            }
            catch (Exception err)
            {
                SocketLogMgt.SetLastError(err);
            }
            finally
            {
                _listener.BeginAccept(new AsyncCallback(OnClientConnect), null);
            }
        }
Beispiel #2
0
 internal void RemoveWorker(ISocketWorker worker)
 {
     lock (_workers)
     {
         _workers.Remove(worker);
     }
     //DisplayWorkers();
 }
Beispiel #3
0
 internal void AddWorker(ISocketWorker worker)
 {
     lock (_workers)
     {
         _workers.Add(worker);
     }
     //DisplayWorkers();
 }