예제 #1
0
        public void Listen(int port, bool enableBroadcast = true, bool exclusiveAddressUse = false, bool ipV6 = false)
        {
            Close();
            _disposable = new CompositeDisposable();

            if (ipV6)
            {
                Client = new UdpClient(AddressFamily.InterNetworkV6);
            }
            else
            {
                Client = new UdpClient();
            }

            Client.EnableBroadcast     = enableBroadcast;
            Client.ExclusiveAddressUse = exclusiveAddressUse;
            if (!exclusiveAddressUse)
            {
                Client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            }
            Client.Client.Bind(new IPEndPoint(LocalAddress.Equals(IPAddress.None) ? (ipV6 ? IPAddress.IPv6Any : IPAddress.Any) : LocalAddress, port));
            _disposable.Add(
                Observable.Defer(() => Client.ReceiveAsync().ToObservable())
                .Repeat()
                .Subscribe(r => _received.OnNext(new UdpData(r.RemoteEndPoint, r.Buffer)))
                );

            IsMulticast = false;
        }
예제 #2
0
        public override bool Equals(object obj)
        {
            var item = obj as Connection;

            if (item == null)
            {
                return(false);
            }

            return(OwnerPid.Equals(item.OwnerPid) &&
                   ExternalPort.Equals(item.ExternalPort) &&
                   LocalPort.Equals(item.LocalPort) &&
                   ExternalAddress.Equals(item.ExternalAddress) &&
                   LocalAddress.Equals(item.LocalAddress) &&
                   Protocol.Equals(item.Protocol) &&
                   State.Equals(item.State));
        }