Ejemplo n.º 1
0
        //    public LocalCertificateSelectionCallback ClientCertificateSelector { get; set; }

        #endregion

        #region Events


        #endregion

        #region Constructor(s)

        #region HTTPClient(RemoteIPAddress, RemotePort, RemoteCertificateValidator = null, ClientCert = null, DNSClient = null)

        /// <summary>
        /// Create a new HTTPClient using the given optional parameters.
        /// </summary>
        /// <param name="RemoteIPAddress">The remote IP address to connect to.</param>
        /// <param name="RemotePort">The remote IP port to connect to.</param>
        /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param>
        /// <param name="ClientCert">The TLS client certificate to use.</param>
        /// <param name="DNSClient">An optional DNS client.</param>
        public HTTPClient(IIPAddress RemoteIPAddress,
                          IPPort RemotePort,
                          RemoteCertificateValidationCallback RemoteCertificateValidator = null,
                          X509Certificate ClientCert = null,
                          DNSClient DNSClient        = null)
        {
            this.RemoteIPAddress            = RemoteIPAddress;
            this.Hostname                   = RemoteIPAddress.ToString();
            this.RemotePort                 = RemotePort;
            this.RemoteCertificateValidator = RemoteCertificateValidator;
            this.ClientCert                 = ClientCert;
            this.DNSClient                  = DNSClient == null
                                                   ? new DNSClient()
                                                   : DNSClient;
        }
Ejemplo n.º 2
0
        private Socket CreateAndConnectTCPSocket(IIPAddress _IPAddress, IPPort Port)
        {
            Socket _TCPSocket = null;

            if (_IPAddress is IPv4Address)
            {
                _TCPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            }

            else if (_IPAddress is IPv6Address)
            {
                _TCPSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
            }

            _TCPSocket.Connect(IPAddress.Parse(_IPAddress.ToString()), Port.ToUInt16());

            return(_TCPSocket);
        }
Ejemplo n.º 3
0
        //    public LocalCertificateSelectionCallback ClientCertificateSelector { get; set; }

        #endregion

        #region Events


        #endregion

        #region Constructor(s)

        #region HTTPClient(RemoteIPAddress, RemotePort, RemoteCertificateValidator = null, ClientCert = null, DNSClient = null)

        /// <summary>
        /// Create a new HTTPClient using the given optional parameters.
        /// </summary>
        /// <param name="RemoteIPAddress">The remote IP address to connect to.</param>
        /// <param name="RemotePort">The remote IP port to connect to.</param>
        /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param>
        /// <param name="ClientCert">The TLS client certificate to use.</param>
        /// <param name="DNSClient">An optional DNS client.</param>
        public HTTPClient(IIPAddress                           RemoteIPAddress,
                          IPPort                               RemotePort,
                          RemoteCertificateValidationCallback  RemoteCertificateValidator  = null,
                          X509Certificate                      ClientCert                  = null,
                          DNSClient                            DNSClient                   = null)
        {

            this.RemoteIPAddress             = RemoteIPAddress;
            this.Hostname                    = RemoteIPAddress.ToString();
            this.RemotePort                  = RemotePort;
            this.RemoteCertificateValidator  = RemoteCertificateValidator;
            this.ClientCert                  = ClientCert;
            this.DNSClient                   = DNSClient == null
                                                   ? new DNSClient()
                                                   : DNSClient;

        }
Ejemplo n.º 4
0
        /// <summary>
        /// Shutdown the UDP receiver.
        /// </summary>
        /// <param name="Message">An optional shutdown message.</param>
        /// <param name="Wait">Wait until the server finally shutted down.</param>
        public void Shutdown(String Message = null,
                             Boolean Wait   = true)
        {
            if (IsMulticast)
            {
                LocalDotNetSocket.SetSocketOption(SocketOptionLevel.IP,
                                                  SocketOptionName.DropMembership,
                                                  new MulticastOption(System.Net.IPAddress.Parse(_IPAddress.ToString()),
                                                                      System.Net.IPAddress.Any));
            }

            this.CancellationTokenSource.Cancel();

            if (Wait)
            {
                while (_IsRunning > 0)
                {
                    Thread.Sleep(10);
                }
            }

            var OnCompletedLocal = OnCompleted;

            if (OnCompletedLocal != null)
            {
                OnCompletedLocal(this, DateTime.Now, Message);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a new UDP receiver listening on the given IP address and port.
        /// </summary>
        /// <param name="IPAddress">The IP address to listen.</param>
        /// <param name="Port">The port to listen.</param>
        /// <param name="ServiceBanner">Service banner.</param>
        /// <param name="Mapper">A delegate to transform the incoming UDP packets into custom data structures.</param>
        /// <param name="ReceiverThreadName">The optional name of the UDP receiver thread.</param>
        /// <param name="ReceiverThreadPriority">The optional priority of the UDP receiver thread.</param>
        /// <param name="ReceiverThreadIsBackground">Whether the UDP receiver thread is a background thread or not.</param>
        /// <param name="PacketThreadsNameCreator">An optional delegate to set the name of the UDP packet threads.</param>
        /// <param name="PacketThreadsPriority">The optional priority of the UDP packet threads.</param>
        /// <param name="PacketThreadsAreBackground">Whether the UDP packet threads are background threads or not.</param>
        /// <param name="Autostart">Start the UDP receiver thread immediately.</param>
        public UDPReceiver(IIPAddress IPAddress,
                           IPPort Port,
                           String ServiceBanner                  = DefaultServiceBanner,
                           MapperDelegate Mapper                 = null,
                           MapReduceDelegate MapReduce           = null,
                           String ReceiverThreadName             = "UDP receiver thread",
                           ThreadPriority ReceiverThreadPriority = ThreadPriority.AboveNormal,
                           Boolean ReceiverThreadIsBackground    = true,
                           Func <UDPPacket <TData>, String> PacketThreadsNameCreator = null,
                           ThreadPriority PacketThreadsPriority = ThreadPriority.AboveNormal,
                           Boolean PacketThreadsAreBackground   = true,
                           Boolean Autostart = false)

        {
            if (Mapper == null && MapReduce == null)
            {
                throw new ArgumentNullException("The mapper and mapreduce delegate can not be both null!");
            }

            this._IPAddress               = IPAddress;
            this._IsMulticast             = IPAddress.IsMulticast;
            this._Port                    = Port;
            this._IPSocket                = new IPSocket(_IPAddress, _Port);
            this.ServiceBanner            = ServiceBanner;
            this.Mapper                   = Mapper;
            this.MapReduce                = MapReduce;
            this._ReceiverThreadName      = ReceiverThreadName;
            this._ReceiverThreadPriority  = ReceiverThreadPriority;
            this.PacketThreadsNameCreator = (PacketThreadsNameCreator == null)
                                                  ? UDPpacket => "UDP packet from " + UDPpacket.RemoteSocket.IPAddress + ":" + UDPpacket.RemoteSocket.Port
                                                  : PacketThreadsNameCreator;
            this._PacketThreadsPriority      = PacketThreadsPriority;
            this._PacketThreadsAreBackground = PacketThreadsAreBackground;

            var LocalIPEndPoint = new IPEndPoint(new System.Net.IPAddress(_IPAddress.GetBytes()), _Port.ToInt32());

            this.LocalSocket       = new IPSocket(LocalIPEndPoint);
            this.LocalDotNetSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            this.LocalDotNetSocket.Bind(LocalIPEndPoint);

            this.BufferSize     = 65536;
            this.ReceiveTimeout = 5000;

            if (IsMulticast)
            {
                LocalDotNetSocket.SetSocketOption(SocketOptionLevel.IP,
                                                  SocketOptionName.AddMembership,
                                                  new MulticastOption(System.Net.IPAddress.Parse(_IPAddress.ToString()),
                                                                      System.Net.IPAddress.Any));
            }

            this.CancellationTokenSource = new CancellationTokenSource();
            this.CancellationToken       = CancellationTokenSource.Token;

            if (Autostart)
            {
                Start();
            }
        }
Ejemplo n.º 6
0
        private Socket CreateAndConnectTCPSocket(IIPAddress _IPAddress, IPPort Port)
        {
            Socket _TCPSocket = null;

            if (_IPAddress is IPv4Address)
                _TCPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            else if (_IPAddress is IPv6Address)
                _TCPSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

            _TCPSocket.Connect(IPAddress.Parse(_IPAddress.ToString()), Port.ToUInt16());

            return _TCPSocket;
        }