示例#1
0
文件: IPEndpoint.cs 项目: wandec/ice
        public override IEnumerable <Endpoint> ExpandHost(out Endpoint?publish)
        {
            publish = null;
            // If this endpoint has an empty host (wildcard address), don't expand, just return this endpoint.
            if (Host.Length == 0)
            {
                return(new Endpoint[] { this });
            }

            // If using a fixed port, this endpoint can be used as the published endpoint to access the returned
            // endpoints. Otherwise, we'll publish each individual expanded endpoint.
            publish = Port > 0 ? this : null;

            IEnumerable <IPEndPoint> addresses = Network.GetAddresses(Host,
                                                                      Port,
                                                                      Communicator.IPVersion,
                                                                      EndpointSelectionType.Ordered,
                                                                      Communicator.PreferIPv6);

            if (addresses.Count() == 1)
            {
                return(new Endpoint[] { this });
            }
            else
            {
                return(addresses.Select(address => CreateEndpoint(Network.EndpointAddressToString(address),
                                                                  Network.EndpointPort(address),
                                                                  ConnectionId,
                                                                  HasCompressionFlag,
                                                                  Timeout)));
            }
        }
示例#2
0
        public ConnectionInfo GetInfo()
        {
            var    info = new TCPConnectionInfo();
            Socket?fd   = _stream.Fd();

            if (fd != null)
            {
                EndPoint localEndpoint = Network.GetLocalAddress(fd);
                info.LocalAddress = Network.EndpointAddressToString(localEndpoint);
                info.LocalPort    = Network.EndpointPort(localEndpoint);
                EndPoint?remoteEndpoint = Network.GetRemoteAddress(fd);
                info.RemoteAddress = Network.EndpointAddressToString(remoteEndpoint);
                info.RemotePort    = Network.EndpointPort(remoteEndpoint);
                info.RcvSize       = Network.GetRecvBufferSize(fd);
                info.SndSize       = Network.GetSendBufferSize(fd);
            }
            return(info);
        }
示例#3
0
        public ConnectionInfo GetInfo()
        {
            var info = new UDPConnectionInfo();

            if (_fd != null)
            {
                EndPoint localEndpoint = Network.GetLocalAddress(_fd);
                info.LocalAddress = Network.EndpointAddressToString(localEndpoint);
                info.LocalPort    = Network.EndpointPort(localEndpoint);
                if (_state == StateNotConnected)
                {
                    if (_peerAddr != null)
                    {
                        info.RemoteAddress = Network.EndpointAddressToString(_peerAddr);
                        info.RemotePort    = Network.EndpointPort(_peerAddr);
                    }
                }
                else
                {
                    EndPoint?remoteEndpoint = Network.GetRemoteAddress(_fd);
                    if (remoteEndpoint != null)
                    {
                        info.RemoteAddress = Network.EndpointAddressToString(remoteEndpoint);
                        info.RemotePort    = Network.EndpointPort(remoteEndpoint);
                    }
                }
                info.RcvSize = Network.GetRecvBufferSize(_fd);
                info.SndSize = Network.GetSendBufferSize(_fd);
            }

            if (_mcastAddr != null)
            {
                info.McastAddress = Network.EndpointAddressToString(_mcastAddr);
                info.McastPort    = Network.EndpointPort(_mcastAddr);
            }
            return(info);
        }
示例#4
0
 public int EffectivePort() => Network.EndpointPort(_addr);