"System.Net.Sockets.SocketException (0x80004005): An attempt was made to access a socket in a way forbidden by its access permissions"
OK I know this problem has occurred many times before on S.O., but I cannot find a solution. Here is my question: what are possible causes of this.
Points:
One more point - this error also happened after porting to .NET Core.
The only change is that I am trying to share ports but I can't see the connection between that and the error.The code to connect is
client = new TcpClient();
client.Client.SetSocketOption(
SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
client.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 0);
client.Client.Bind(ipLocalEndPoint);
client.Client.Connect(ep);
where the local endpoint is reused.
What are the possible causes of this error? It is happening on every BIND call.
OK this all turned out to be me being incredibly stupid.
What I had done, and forgotten I had done, is establish a TcpListener on the same port, with this code _tcpListener.ExclusiveAddressUse = false;
not working as I expected.
User contributions licensed under CC BY-SA 3.0