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


C# UdpClient.AllowNatTraversal方法代码示例

本文整理汇总了C#中System.Net.Sockets.UdpClient.AllowNatTraversal方法的典型用法代码示例。如果您正苦于以下问题:C# UdpClient.AllowNatTraversal方法的具体用法?C# UdpClient.AllowNatTraversal怎么用?C# UdpClient.AllowNatTraversal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Sockets.UdpClient的用法示例。


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

示例1: UdpReceiver

 /// <summary>
 /// UDP接收器
 /// </summary>
 /// <param name="listenPort">监听的端口</param>
 public UdpReceiver(int listenPort)
 {
   this.Encoding = Encoding.Default;
   this.ListenPort = listenPort;
   udpClient = new UdpClient(listenPort);
   udpClient.AllowNatTraversal(true);
 }
开发者ID:sclcwwl,项目名称:Gimela,代码行数:11,代码来源:UdpReceiver.cs

示例2: OnConnect

		protected override void OnConnect()
		{
			_udp = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
			_udp.AllowNatTraversal(true);
			_isReady = false;
			_isClearing = false;
        }
开发者ID:Mercurial,项目名称:Discord.Net,代码行数:7,代码来源:DiscordVoiceSocket.cs

示例3: UdpFactory

 public UdpFactory(int port)
 {
     ListenPort = port;
     udpClient = new UdpClient(port);
     udpClient.DontFragment = false;
     udpClient.AllowNatTraversal(true);
 }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:7,代码来源:UdpFactory.cs

示例4: UdpStreamSender

        public UdpStreamSender()
        {
            _queue = new ConcurrentQueue<StreamPacket>();
              _waiter = new ManualResetEvent(false);

              _udpClient = new UdpClient();
              _udpClient.AllowNatTraversal(true);

              _senderThread = new Thread(new ThreadStart(WorkThread));
        }
开发者ID:sclcwwl,项目名称:Gimela,代码行数:10,代码来源:UdpStreamSender.cs

示例5: UdpServerHandler

        /// <summary>
        /// Instantiates an instances of the UdpServerHandler class using the specified SocketBinder and parameters.
        /// </summary>
        /// <param name="binder">SocketBinder to bind a new socket too.</param>
        /// <param name="port">Port used for receiving.</param>
        /// <param name="alignment">Default alignment in bytes for buffers.</param>
        /// <param name="packetHeader">Collection of bytes used for packet verification.</param>
        public UdpServerHandler( SocketBinder binder, int port, int alignment )
            : base(binder)
        {
            Port = port;
            Alignment = ( alignment > 0 ) ? alignment : 1;
            running = false;

            Listener = new UdpClient( port );
            Listener.EnableBroadcast = true;
            Listener.AllowNatTraversal( true );
        }
开发者ID:FatalSleep,项目名称:Sharp-Server,代码行数:18,代码来源:UdpServerHandler.cs

示例6: ReceiveOperation

 public ReceiveOperation(int opId, List<short> tOrder, ushort port)
 {
     client = new UdpClient(AddressFamily.InterNetworkV6);
     client.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
     client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
     client.AllowNatTraversal(true);
     client.Client.Bind(new IPEndPoint(IPAddress.IPv6Any, port));
     totalCount = tOrder.Count;
     order = tOrder;
     operationID = opId;
 }
开发者ID:ItsElioBaby,项目名称:UDP-Router,代码行数:11,代码来源:ReceiveOperation.cs

示例7: SendOperation

 public SendOperation(IPEndPoint dest, Packet[] data, int opId)
 {
     destination = dest;
     table = new Dictionary<short, byte[]>();
     foreach (Packet p in data)
         table.Add(p.HandshakeID, p._data);
     operationID = opId;
     client = new UdpClient(AddressFamily.InterNetworkV6);
     client.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
     client.AllowNatTraversal(true);
     client.Connect(dest);
 }
开发者ID:ItsElioBaby,项目名称:UDP-Router,代码行数:12,代码来源:SendOperation.cs

示例8: Initialize

 public void Initialize(int port)
 {
     Log.Debug("UDP Service Initializing on port..." + port);
     _base = new UdpClient(AddressFamily.InterNetworkV6);
     _base.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
     _base.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);   // Maybe change this to true to extend security ?
     _base.AllowNatTraversal(true);
     _base.Client.Bind(new IPEndPoint(IPAddress.IPv6Any, port));
     _base.Client.SendBufferSize = 3 * 1024;
     _base.Client.ReceiveBufferSize = 3 * 1024;
     new Thread(xrun).Start();
 }
开发者ID:ItsElioBaby,项目名称:ImagineNET,代码行数:12,代码来源:UdpService.cs

示例9: retrieveHostEntries

 public void retrieveHostEntries()
 {
     string hostName = Dns.GetHostName();
     foreach (IPAddress interfaceIP in (from ip in Dns.GetHostEntry(hostName).AddressList where ip.AddressFamily == AddressFamily.InterNetwork select ip))
     {
         UdpClient client = new UdpClient();
         client.AllowNatTraversal(true);
         client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
         client.Client.Bind(new IPEndPoint(interfaceIP, multicastGroup.Port));
         client.JoinMulticastGroup(this.multicastGroup.Address);
         this.hostEntries.Add(client);
     }
 }
开发者ID:ahmad-siavashi,项目名称:Multicast-Receiver,代码行数:13,代码来源:Listener.cs

示例10: Listen

 public void Listen()
 {
     foreach (var IP in (from ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList where ip.AddressFamily == AddressFamily.InterNetwork select ip.ToString()).ToList())
     {
         UdpClient UdpClient = new UdpClient();
         UdpClient.AllowNatTraversal(true);
         LocalEntryPoint = new IPEndPoint(IPAddress.Parse(IP), MulticastAddress.Port);
         UdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
         UdpClient.Client.Bind(LocalEntryPoint);
         UdpClient.JoinMulticastGroup(MulticastAddress.Address, IPAddress.Parse(IP));
         UdpClient.BeginReceive(ReceiveCallBack, new object[] {
              UdpClient, new IPEndPoint(IPAddress.Parse(IP), ((IPEndPoint)UdpClient.Client.LocalEndPoint).Port)
             });
     }
 }
开发者ID:ahmad-siavashi,项目名称:Project-Bella,代码行数:15,代码来源:Listener.cs

示例11: Initialize

        public static void Initialize(short port, Action<Packet> rcvHandler)
        {
            client = new UdpClient(AddressFamily.InterNetworkV6);
            client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            client.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
            client.AllowNatTraversal(true);
            client.Client.Bind(new IPEndPoint(IPAddress.IPv6Any, port));

            Log.Debug("Initialized UDP Router");
            handler = rcvHandler;
            client.BeginReceive(endReceive, null);
            Thread t = new Thread(clear_pending);
            t.IsBackground = true;
            t.Start();
        }
开发者ID:ItsElioBaby,项目名称:UDP-Router,代码行数:15,代码来源:UdpPacketRouter.cs

示例12: UdpSender

    /// <summary>
    /// UDP发送器
    /// </summary>
    /// <param name="sentToAddress">发送目的地址</param>
    /// <param name="sentToPort">发送目的端口</param>
    public UdpSender(string sentToAddress, int sentToPort)
    {
      Address = sentToAddress;
      Port = sentToPort;

      this.Encoding = Encoding.Default;

      queue = new ConcurrentQueue<byte[]>();
      waiter = new ManualResetEvent(false);

      udpClient = new UdpClient();
      udpClient.AllowNatTraversal(true);

      senderThread = new Thread(new ThreadStart(WorkThread));
    }
开发者ID:sclcwwl,项目名称:Gimela,代码行数:20,代码来源:UdpSender.cs

示例13: Cast

 public void Cast()
 {
     UdpClients = new List<UdpClient>();
     string HostName = Dns.GetHostName();
     foreach (var IP in (from ip in Dns.GetHostEntry(HostName).AddressList where ip.AddressFamily == AddressFamily.InterNetwork select ip.ToString()).ToList())
     {
         UdpClient UdpClient = new UdpClient(new IPEndPoint(IPAddress.Parse(IP), 0));
         UdpClient.AllowNatTraversal(true);
         UdpClient.JoinMulticastGroup(MulticastGroup.Address);
         UdpClients.Add(UdpClient);
     }
     string Message = "iam:" + HostName;
     byte[] Data = Encoding.ASCII.GetBytes(Message.ToCharArray());
     while (true)
     {
         foreach (UdpClient client in UdpClients)
         {
             client.BeginSend(Data, Data.Length, MulticastGroup, null, null);
         }
         Thread.Sleep(CastDelay);
     }
 }
开发者ID:ahmad-siavashi,项目名称:Project-Bella,代码行数:22,代码来源:Multicaster.cs

示例14: Restart

 /// <summary>
 /// Closes, resets and restarts the UDP server.
 /// </summary>
 public void Restart()
 {
     Close();
     Listener = new UdpClient( Port );
     Listener.EnableBroadcast = true;
     Listener.AllowNatTraversal( true );
     Status = false;
     running = false;
     Start();
 }
开发者ID:FatalSleep,项目名称:Sharp-Server,代码行数:13,代码来源:UdpServerHandler.cs

示例15: AutoDetectServers

		private void AutoDetectServers()
		{
			// 33848
			try
			{
				UdpClient client = new UdpClient(555);
				client.AllowNatTraversal(true);
				client.EnableBroadcast = true;
				client.Connect(IPAddress.Parse("255.255.255.255"), 33848);
				byte[] message = Encoding.ASCII.GetBytes("Hello");
				client.Send(message, message.Length);
				var response = client.ReceiveAsync();
				response.ContinueWith(x =>
				{
					if (!x.IsFaulted)
					{
						var temp = x.Result;
						string data = Encoding.UTF8.GetString(temp.Buffer);
						var xml = XElement.Parse(data);
						var urlElement = xml.Elements("url").FirstOrDefault();
						AddServers(new[] { (string) urlElement });
					}
				}, TaskScheduler.FromCurrentSynchronizationContext());

			}
			catch (Exception e)
			{
				s_logger.Error(e.Message, e);
			}
		}
开发者ID:kveretennicov,项目名称:kato,代码行数:30,代码来源:AppModel.cs


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