Esempio n. 1
0
        public Sender(Log log, Statistics statistics, ProgramConfiguration programConfiguration)
            : base(log, programConfiguration)
        {
            var destinationEndPoint =
                new IPEndPoint(_programConfiguration.DestinationIpAddress, programConfiguration.DestinationPort);

            _networkProtocol =
                new UdpNetworkProtocol(
                    log, statistics, destinationEndPoint, UdpNetworkProtocolType.Udp, _programConfiguration.PacketSize,
                    _programConfiguration.VerifyOrder);

            _sendDataTask =
                new HighResolutionTimer
            {
                Mode       = TimerMode.Periodic,
                Period     = 1000,
                Resolution = 0,
                IsAsync    = true
            };

            _sendDataTask.Tick += (sender, args) => SendData();

            var bindedIp =
                MachineAddress.FirstOrDefault(i => i.Equals(_programConfiguration.SourceIpAddress)) ?? IPAddress.Any;

            var bindedPort = programConfiguration.SourcePort ?? 0;

            _networkProtocol.Bind(new IPEndPoint(bindedIp, bindedPort));

            if (programConfiguration.NetworkBufferSize.HasValue)
            {
                _networkProtocol.SetSendBufferSize(programConfiguration.NetworkBufferSize.Value);
            }
        }
        public Receiver(Log log, Statistics statistics, ProgramConfiguration programConfiguration)
            : base(log, programConfiguration)
        {
            var destinationEndPoint =
                new IPEndPoint(_programConfiguration.DestinationIpAddress, programConfiguration.DestinationPort);

            _networkProtocol =
                new UdpNetworkProtocol(
                    log, statistics, destinationEndPoint, UdpNetworkProtocolType.Udp, _programConfiguration.PacketSize,
                    _programConfiguration.VerifyOrder);

            var bindedIp =
                MachineAddress.FirstOrDefault(i => i.Equals(_programConfiguration.SourceIpAddress)) ?? IPAddress.Any;

            var bindedPort = programConfiguration.SourcePort ?? programConfiguration.DestinationPort;

            _networkProtocol.Bind(new IPEndPoint(bindedIp, bindedPort));

            if (programConfiguration.NetworkBufferSize.HasValue)
            {
                _networkProtocol.SetReceiveBufferSize(programConfiguration.NetworkBufferSize.Value);
            }
        }