- Home /
How to fix AllowNatTraversal or IPProtectionLevel ?
I want to allow nat traversal for my udp connections. We can try 2-3 ways:
System.Net.Sockets.UdpClient u1 = new UdpClient();
u1.AllowNatTraversal( true );
or
System.Net.Sockets.Socket u2 = new Socket( AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
u2.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.IPProtectionLevel, 10 );
or
u2.SetIPProtectionLevel( IPProtectionLevel.Unrestricted );
Mono compiling code without any errors. It configured with .net 4.0
But the Editor show the errors:
Type `System.Net.Sockets.UdpClient' does not contain a definition for `AllowNatTraversal' and no extension method `AllowNatTraversal' of type `System.Net.Sockets.UdpClient' could be found (are you missing a using directive or an assembly reference?)
and
`System.Net.Sockets.SocketOptionName' does not contain a definition for `IPProtectionLevel'
and
Type `System.Net.Sockets.Socket' does not contain a definition for `SetIPProtectionLevel' and no extension method `SetIPProtectionLevel' of type `System.Net.Sockets.Socket' could be found (are you missing a using directive or an assembly reference?)
What we can do?
Comment
Answer by Imtnt · Mar 12, 2016 at 02:48 PM
Unity uses .NET 2.0 subset or (.NET 2.0), so .NET 4.0 stuff won't work.
Your answer
![](https://koobas.hobune.stream/wayback/20220612051940im_/https://answers.unity.com/themes/thub/images/avi.jpg)