Exemplo n.º 1
0
        private void _acceptor_OnClientConnected(object sender, ClientConnectedEventArgs args)
        {
            try
            {
                logger.Info("Recebeu conexao. Conectando initiator em [" + conflatedServer + ":" + conflatedPort + "]");

                compressedStream = new MemoryStream();
                //zlib = new Ionic.Zlib.ZlibStream(compressedStream, Ionic.Zlib.CompressionMode.Decompress, true);
                //zlib.BufferSize = BUFFER_SIZE;
                zlib = new ICSharpCode.SharpZipLib.Zip.Compression.Inflater();
                //zlib.FlushMode = Ionic.Zlib.FlushType.Full;

                _initiator.Port   = conflatedPort.ToString();
                _initiator.IpAddr = conflatedServer;
                _initiator.OpenConnection();
            }
            catch (Exception ex)
            {
                logger.Error("_acceptor_OnClientConnected: " + ex.Message, ex);
            }
        }
Exemplo n.º 2
0
        private void OnClientConnect(IAsyncResult asyn)
        {
            try
            {
                Socket ActiveSocket = MainSocket.EndAccept(asyn);

                Interlocked.Increment(ref ClientCount);
                this.WaitForData(ActiveSocket, ClientCount);

                lock (HashActiveClients)
                {
                    if (HashActiveClients.ContainsKey(ClientCount))
                    {
                        HashActiveClients[ClientCount] = ActiveSocket;
                    }
                    else
                    {
                        HashActiveClients.Add(ClientCount, ActiveSocket);
                    }
                }

                ClientConnectedEventArgs args = new ClientConnectedEventArgs();

                args.ClientNumber = ClientCount;
                args.ClientSocket = ActiveSocket;

                if (OnClientConnected != null)
                {
                    OnClientConnected(this, args);
                }

                MainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
            }

            catch (SocketException se)
            {
                logger.Error("OnClientConnect(): " + se.Message, se);
                throw se;
            }
        }