public AsyncTransportChannel(SocketAsyncEventArgs receiveEventArgs, SocketAsyncEventArgs sendEventArgs, NetworkSettings settings)
        {
            _receiveSAEA = receiveEventArgs;
            _sendSAEA = sendEventArgs;
            _networkSettings = settings;
            _packetReceiverLogic = new PacketReceiverLogic(settings.BufferSize, settings.ReceivePrefixLength);
            _packetSenderLogic = new PacketSenderLogic(settings.BufferSize, settings.SendPrefixLength);

            Initialize();
        }
Beispiel #2
0
        // Constructor.
        public SocketListener(NetworkSettings theNetworkSettings)
        {
            this._networkSettings = theNetworkSettings;
            //Allocate memory for buffers. We are using a separate buffer space for
            //receive and send, instead of sharing the buffer space, like the Microsoft
            //example does.
            this._theBufferManager = new BufferManager(this._networkSettings.ReceiveBufferSize * this._networkSettings.NumberOfSaeaForRecSend * this._networkSettings.OpsToPreAllocate,
            this._networkSettings.ReceiveBufferSize);

            this._poolOfReceiveEventArgs = new SocketAsyncEventArgsPool(this._networkSettings.NumberOfSaeaForRecSend);
            this._poolOfSendEventArgs = new SocketAsyncEventArgsPool(this._networkSettings.NumberOfSaeaForRecSend);
            this._poolOfAcceptEventArgs = new SocketAsyncEventArgsPool(this._networkSettings.MaxSimultaneousAcceptOps);

            // Create connections count enforcer
            this._theMaxConnectionsEnforcer = new Semaphore(this._networkSettings.MaxConnections, this._networkSettings.MaxConnections);

            ActiveChannels = new ObservableCollection<AsyncTransportChannel>();

            //Microsoft's example called these from Main method, which you
            //can easily do if you wish.
            Init();
            StartListen();
        }
Beispiel #3
0
        public static NetworkSettings GetFromAppConfig()
        {
            var result = new NetworkSettings();
            result.Backlog = int.Parse(ConfigurationManager.AppSettings["backLog"]);
            result.MaxConnections = int.Parse(ConfigurationManager.AppSettings["maxNumberOfConnections"]);
            result.ReceiveBufferSize = int.Parse(ConfigurationManager.AppSettings["bufferSize"]);
            result.ReceivePrefixLength = int.Parse(ConfigurationManager.AppSettings["receivePrefixLength"]);
            result.SendPrefixLength = int.Parse(ConfigurationManager.AppSettings["sendPrefixLength"]);
            result.MaxSimultaneousAcceptOps = int.Parse(ConfigurationManager.AppSettings["maxSimultaneousAcceptOps"]);
            result.OpsToPreAllocate = int.Parse(ConfigurationManager.AppSettings["opsToPreAlloc"]);
            result.ExcessSaeaObjectsInPool = int.Parse(ConfigurationManager.AppSettings["excessSaeaObjectsInPool"]);

            if (ConfigurationManager.AppSettings.AllKeys.Any(k => k.Equals("endpointAdr")))
            {
                result.LocalEndPoint = new IPEndPoint(
                    IPAddress.Parse(ConfigurationManager.AppSettings["endpointAdr"]),
                    int.Parse(ConfigurationManager.AppSettings["port"]));
            }
            else
            {
                result.LocalEndPoint = new IPEndPoint(
                   IPAddress.Any,
                   int.Parse(ConfigurationManager.AppSettings["port"]));
            }

            return result;
        }