本文整理汇总了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);
}
示例2: OnConnect
protected override void OnConnect()
{
_udp = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
_udp.AllowNatTraversal(true);
_isReady = false;
_isClearing = false;
}
示例3: UdpFactory
public UdpFactory(int port)
{
ListenPort = port;
udpClient = new UdpClient(port);
udpClient.DontFragment = false;
udpClient.AllowNatTraversal(true);
}
示例4: UdpStreamSender
public UdpStreamSender()
{
_queue = new ConcurrentQueue<StreamPacket>();
_waiter = new ManualResetEvent(false);
_udpClient = new UdpClient();
_udpClient.AllowNatTraversal(true);
_senderThread = new Thread(new ThreadStart(WorkThread));
}
示例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 );
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
}
示例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)
});
}
}
示例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();
}
示例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));
}
示例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);
}
}
示例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();
}
示例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);
}
}