当前位置: 首页>>代码示例>>C#>>正文


C# AddressFamily类代码示例

本文整理汇总了C#中AddressFamily的典型用法代码示例。如果您正苦于以下问题:C# AddressFamily类的具体用法?C# AddressFamily怎么用?C# AddressFamily使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AddressFamily类属于命名空间,在下文中一共展示了AddressFamily类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSocket

 public Socket CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
 {
     SetAddressFamily(addressFamily);
     SetProtocolType(protocolType);
     SetSocketType(socketType);
     return new Socket(this.addressFamily, this.socketType, this.protocolType);
 }
开发者ID:julfycoder,项目名称:Sniffer,代码行数:7,代码来源:SocketBuilder.cs

示例2: IPAddress

        /// <devdoc>
        ///    <para>
        ///       Constructor for an IPv6 Address with a specified Scope.
        ///    </para>
        /// </devdoc>
        public IPAddress(byte[] address,long scopeid) {

            if (address==null) {
                throw new ArgumentNullException("address");
            }

            if(address.Length != IPv6AddressBytes){
                throw new ArgumentException(SR.GetString(SR.dns_bad_ip_address), "address");
            }

            m_Family = AddressFamily.InterNetworkV6;

            for (int i = 0; i < NumberOfLabels; i++) {
                m_Numbers[i] = (ushort)(address[i * 2] * 256 + address[i * 2 + 1]);
            }

            //
            // Consider: Since scope is only valid for link-local and site-local
            //           addresses we could implement some more robust checking here
            //
            if ( scopeid < 0 || scopeid > 0x00000000FFFFFFFF ) {
                throw new ArgumentOutOfRangeException("scopeid");
            }

            m_ScopeId = scopeid;
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:31,代码来源:IPAddress.cs

示例3: GetDisposedSocket

 private static Socket GetDisposedSocket(AddressFamily addressFamily = AddressFamily.InterNetwork)
 {
     using (var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp))
     {
         return socket;
     }
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:7,代码来源:DisposedSocketTests.cs

示例4: UdpClient

 public UdpClient(int port, AddressFamily family)
 {
     IPEndPoint point;
     this.m_Buffer = new byte[0x10000];
     this.m_Family = AddressFamily.InterNetwork;
     if (!ValidationHelper.ValidateTcpPort(port))
     {
         throw new ArgumentOutOfRangeException("port");
     }
     if ((family != AddressFamily.InterNetwork) && (family != AddressFamily.InterNetworkV6))
     {
         throw new ArgumentException(SR.GetString("net_protocol_invalid_family"), "family");
     }
     this.m_Family = family;
     if (this.m_Family == AddressFamily.InterNetwork)
     {
         point = new IPEndPoint(IPAddress.Any, port);
     }
     else
     {
         point = new IPEndPoint(IPAddress.IPv6Any, port);
     }
     this.createClientSocket();
     this.Client.Bind(point);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:UdpClient.cs

示例5: init

        /// <summary>
        /// Initializes the socket
        /// </summary>`
        public void init(int offset, string ipAddress)
        {
            socketType = SocketType.Stream;
            protocolType = ProtocolType.Tcp;
            //addressFamily = AddressFamily.InterNetwork;
            addressFamily = AddressFamily.InterNetwork;
            try
            {
                ipEntry = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress[] addr = ipEntry.AddressList;
                //endpoint = new IPEndPoint(addr[0], port);
                for (int i = 0; i < addr.Length; i++)
                {
                    Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString());
                }
                if (ipAddress == "")
                {
                    address = addr[addr.Length - offset];
                }
                else
                {
                    address = IPAddress.Parse(ipAddress);
                }
                Console.WriteLine("Using the Address {0}: {1}", address.ToString(), port);
                endpoint = new IPEndPoint(address, port);
            }
            catch (SocketException ex)
            {
                System.Console.WriteLine(ex.Message);
            }
            createSocket();

        }
开发者ID:EricYoung2011,项目名称:iMonopolyDeal,代码行数:36,代码来源:ServerSocket.cs

示例6: TestAddressFamilyObsolete

        public void TestAddressFamilyObsolete(bool ipv6, AddressFamily addressFamily)
        {
#pragma warning disable 618
            var settings = new MongoServerSettings { IPv6 = ipv6 };
            Assert.AreEqual(addressFamily, settings.AddressFamily);
#pragma warning restore
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoServerSettingsTests.cs

示例7: SocketManager

 public SocketManager(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
 {
     _addressFamily = addressFamily;
     _socketType = socketType;
     _protocolType = protocolType;
     _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 }
开发者ID:MagnusTiberius,项目名称:WalkerRoad,代码行数:7,代码来源:SocketManager.cs

示例8: IPAddressRange

        /// <param name="ipRangeStr">
        /// e.g)
        /// "10.23.0.0/24",
        /// "127.0.0.1" (equals to "127.0.0.1/32"),
        /// "2001:0db8:bd05:01d2:288a:1fc0:0001:0000/16",
        /// "::1" (equals to "::1/128")
        /// </param>
        public IPAddressRange(string ipRangeString)
        {
            if (string.IsNullOrEmpty(ipRangeString))
                throw new InvalidOperationException("IP Address is null or empty.");

            var vals = ipRangeString.Split('/');
            IPAddress ipAddr;
            if (!IPAddress.TryParse(vals[0], out ipAddr))
                throw new InvalidOperationException(string.Format("IP Address({0}) is invalid format.", ipRangeString));

            _addressFamily = ipAddr.AddressFamily;
            if (_addressFamily != AddressFamily.InterNetwork && _addressFamily != AddressFamily.InterNetworkV6)
                throw new InvalidOperationException(string.Format("IP Address({0}) is not ip4 or ip6 address famiry.", ipRangeString));

            var maxMaskRange = _addressFamily == AddressFamily.InterNetwork ? 32 : 128;
            int maskRange;
            if (vals.Length > 1)
            {
                if (!int.TryParse(vals[1], out maskRange) || maskRange < 0 || maskRange > maxMaskRange)
                    throw new InvalidOperationException(string.Format("IP Address({0}) is invalid range.", ipRangeString));
            }
            else
                maskRange = maxMaskRange;

            _netowrkAddressBytes = ipAddr.GetAddressBytes();
            _subnetMaskBytes = Enumerable.Repeat<byte>(0xFF, _netowrkAddressBytes.Length).ToArray();

            for (int i = 0; i < (maxMaskRange - maskRange); i++)
                _subnetMaskBytes[_subnetMaskBytes.Length - 1 - i / 8] -= (byte)(1 << (i % 8));
        }
开发者ID:TheObliterator,项目名称:HttpAuthModule,代码行数:37,代码来源:IPAddressRange.cs

示例9: SocketServer

        public SocketServer(int portNumber, AddressFamily addressFamily, SocketType socketType,
            ProtocolType protocolType)
        {
            this.portNumber = portNumber;
            this.addressFamily = addressFamily;
            this.socketType = socketType;
            this.protocolType = protocolType;

            clientAddresses = new List<string>();
            clientTable = new Dictionary<string, StateObject>();
            recentlyReceivedStates = new List<StateObject>();
            removeList = new List<string>();

            listenEvent = new ManualResetEvent(false);
            shutDownEvent = new ManualResetEvent(false);
            sendEvent = new ManualResetEvent(false);

            listener = null;
            sendBufferSize = INITIAL_BUFFER_SIZE;
            recvBufferSize = INITIAL_BUFFER_SIZE;
            ShutdownWaitTimeout = 5000;

            enableEncryption = false;
            initialized = false;
            copyingRecvBuffer = false;
            isShuttingDown = false;
            transmittingData = false;
            receivingData = false;
        }
开发者ID:NinjaSteph,项目名称:SureShot,代码行数:29,代码来源:SocketServer.cs

示例10: RawSocket

 public RawSocket(AddressFamily family, SocketProvider provider)
 {
     m_rawsock = new Socket(family, SocketType.Raw, ProtocolType.IP);
     m_rawsock.Blocking = false;
     m_Provider = provider;
     m_ReceivedData = new AsyncCallback(OnReceive);
 }
开发者ID:Ampy,项目名称:NetworkMonitor.Net,代码行数:7,代码来源:RawSocket.cs

示例11: Button_Click

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
           
           // Timer a = new Timer();
//
            //Ping pingSender = new Ping();
            ////for(int i=0;i<30;i++)
            ////{
            //  //  MessageBox.Show(adr);
               String adr ="172.16.16.10";
                IPAddress address = IPAddress.Parse(adr);
            //  //  pingSender.SendAsync(address,250,new PingOptions(5,true));
            // pingSender.SendAsync(address, 250);
           
            //pingSender.PingCompleted += (a, b) =>
            //{
            //    if (b.Reply.Status == IPStatus.Success)
            //    {
            //        MessageBox.Show(b.ToString());
            //    }
            //    else
            //    {
            //        MessageBox.Show("failed");
            //    }

            //};
            //PingReply reply = await pingSender.SendPingAsync(address);

            //if (reply.Status == IPStatus.Success)
            //{
            //    ListBox1.Items.Add(adr);
            //}
            //else
            //{
            //    ListBox2.Items.Add("Failed "+adr); // MessageBox.Show("falied" + adr);
            //}
            //}  
            AddressFamily d=new AddressFamily();

            try
            {
                Ping s=new Ping();
                var a= s.SendPingAsync(address).GetAwaiter();
               a.OnCompleted(() => MessageBox.Show(a.GetResult().Status.ToString()));
               //UdpClient udp=new UdpClient(8080);
               // udp.Connect(address,8080);
               // var a=new byte[]{1,2};
               // await udp.SendAsync(a,44);
               // TcpClient tcp = new TcpClient();
                //await tcp.ConnectAsync(adr, 8080);
               // MessageBox.Show(adr);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }
开发者ID:prabaprakash,项目名称:Visual-Studio-2013,代码行数:60,代码来源:MainWindow.xaml.cs

示例12: Reset

			public void Reset (Socket socket, IPEndPoint ip)
			{
				this.addressFamily = socket.AddressFamily;
				this.socketType = socket.SocketType;
				this.protocolTtype = socket.ProtocolType;
				this.RemoteEndPoint = ip;
			}
开发者ID:learnUnity,项目名称:KU_NET,代码行数:7,代码来源:AsyncSocket.cs

示例13: DnsEndPoint

        public DnsEndPoint(string host, int port, AddressFamily addressFamily)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            if (String.IsNullOrEmpty(host))
            {
                throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(host)));
            }

            if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException(nameof(port));
            }

            if (addressFamily != AddressFamily.InterNetwork &&
                addressFamily != AddressFamily.InterNetworkV6 &&
                addressFamily != AddressFamily.Unspecified)
            {
                throw new ArgumentException(SR.net_sockets_invalid_optionValue_all, nameof(addressFamily));
            }

            _host = host;
            _port = port;
            _family = addressFamily;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:28,代码来源:DnsEndPoint.cs

示例14: Address

 /// <summary>
 /// Initializes a new instance of the <see cref="Address"/> class.
 /// </summary>
 /// <param name="addressFamily">The IP address family</param>
 /// <param name="address">The IP address</param>
 /// <param name="port">The port</param>
 public Address(AddressFamily addressFamily, string address, int port)
 {
     _isEnhanced = true;
     AddressFamily = addressFamily;
     IpAddress = address;
     IpPort = port;
 }
开发者ID:mutac,项目名称:FtpServer,代码行数:13,代码来源:Address.cs

示例15: IsProtocolSupported

        private static bool IsProtocolSupported(AddressFamily af)
        {
            int family;
            switch (af)
            {
                case AddressFamily.InterNetwork:
                    family = Interop.libc.AF_INET;
                    break;
                case AddressFamily.InterNetworkV6:
                    family = Interop.libc.AF_INET6;
                    break;
                default:
                    Debug.Fail("Invalid address family: " + af.ToString());
                    throw new ArgumentException("af");
            }

            int socket = -1;
            try
            {
                socket = Interop.libc.socket(family, Interop.libc.SOCK_DGRAM, 0);
                if (socket == -1)
                {
                    return Interop.Sys.GetLastError() != Interop.Error.EAFNOSUPPORT;
                }
                return true;
            }
            finally
            {
                if (socket != -1)
                {
                    Interop.Sys.Close(socket);
                }
            }
        }
开发者ID:nblumhardt,项目名称:corefx,代码行数:34,代码来源:SocketProtocolSupportPal.Unix.cs


注:本文中的AddressFamily类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。