• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AddressFamily类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: UdpClient

 public UdpClient(int port, AddressFamily family)
 {
     IPEndPoint point;
     this.family = AddressFamily.InterNetwork;
     if ((family != AddressFamily.InterNetwork)
      //   && (family != AddressFamily.InterNetworkV6)
         )
     {
         throw new ArgumentException("Family must be InterNetwork or InterNetworkV6", "family");
     }
     if ((port < 0) || (port > 65535))
     {
         throw new ArgumentOutOfRangeException("port");
     }
     this.family = family;
       //  if (family == AddressFamily.InterNetwork)
     {
         point = new IPEndPoint(IPAddress.Any, port);
     }
     //else
     //{
     //    point = new IPEndPoint(IPAddress.IPv6Any, port);
     //}
     this.InitSocket(point);
 }
开发者ID:memsom,项目名称:dotNetAnywhere-wb,代码行数:25,代码来源:UdpClient.cs


示例17: Socket_internal

		private IntPtr Socket_internal(AddressFamily family,
		SocketType type,
		ProtocolType proto,
		out int error)
		{
			throw new System.NotImplementedException();
		}
开发者ID:desunit,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:Socket_2_1.Mosa.cs


示例18: ProxySocket

 /// <summary>
 /// Initializes a new instance of the ProxySocket class.
 /// </summary>
 /// <param name="addressFamily">One of the AddressFamily values.</param>
 /// <param name="socketType">One of the SocketType values.</param>
 /// <param name="protocolType">One of the ProtocolType values.</param>
 /// <param name="proxyUsername">The username to use when authenticating with the proxy server.</param>
 /// <param name="proxyPassword">The password to use when authenticating with the proxy server.</param>
 /// <exception cref="SocketException">The combination of addressFamily, socketType, and protocolType results in an invalid socket.</exception>
 /// <exception cref="ArgumentNullException"><c>proxyUsername</c> -or- <c>proxyPassword</c> is null.</exception>
 public ProxySocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, string proxyUsername, string proxyPassword)
     : base(addressFamily, socketType, protocolType)
 {
     ProxyUser = proxyUsername;
     ProxyPass = proxyPassword;
     ToThrow = new InvalidOperationException();
 }
开发者ID:0x0mar,项目名称:Xploit,代码行数:17,代码来源:ProxySocket.cs


示例19: CreateSocket

        public static unsafe SafeCloseSocket CreateSocket(SocketInformation socketInformation, out AddressFamily addressFamily, out SocketType socketType, out ProtocolType protocolType)
        {
            SafeCloseSocket handle;
            Interop.Winsock.WSAPROTOCOL_INFO protocolInfo;

            fixed (byte* pinnedBuffer = socketInformation.ProtocolInformation)
            {
                handle = SafeCloseSocket.CreateWSASocket(pinnedBuffer);
                protocolInfo = (Interop.Winsock.WSAPROTOCOL_INFO)Marshal.PtrToStructure<Interop.Winsock.WSAPROTOCOL_INFO>((IntPtr)pinnedBuffer);
            }

            if (handle.IsInvalid)
            {
                SocketException e = new SocketException();
                if (e.SocketErrorCode == SocketError.InvalidArgument)
                {
                    throw new ArgumentException(SR.net_sockets_invalid_socketinformation, "socketInformation");
                }
                else
                {
                    throw e;
                }
            }

            addressFamily = protocolInfo.iAddressFamily;
            socketType = (SocketType)protocolInfo.iSocketType;
            protocolType = (ProtocolType)protocolInfo.iProtocol;
            return handle;
        }
开发者ID:vbouret,项目名称:corefx,代码行数:29,代码来源:SocketPal.Windows.cs


示例20: SetAddressFamily

        public static unsafe void SetAddressFamily(byte[] buffer, AddressFamily family)
        {
            fixed (byte* rawAddress = buffer)
            {
                var sockaddr = (Interop.libc.sockaddr*)rawAddress;
                Interop.CheckBounds((byte*)sockaddr, buffer.Length, &sockaddr->sa_family);

                switch (family)
                {
                    case AddressFamily.Unspecified:
                        sockaddr->sa_family = Interop.libc.AF_UNSPEC;
                        break;

                    case AddressFamily.Unix:
                        sockaddr->sa_family = Interop.libc.AF_UNIX;
                        break;

                    case AddressFamily.InterNetwork:
                        sockaddr->sa_family = Interop.libc.AF_INET;
                        break;

                    case AddressFamily.InterNetworkV6:
                        sockaddr->sa_family = Interop.libc.AF_INET6;
                        break;

                    default:
                        Debug.Fail("Unsupported addres family");
                        throw new PlatformNotSupportedException();
                }
            }
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:31,代码来源:SocketAddressPal.Unix.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AddressOp类代码示例发布时间:2022-05-24
下一篇:
C# Address类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap