"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:
- Happens irrespective of firewall
- Ports are open
- Destination is open and connections have been working in the past
- Since working connections, no changes to firewalls or virus scanners, can rule those out.
- Running as administrative user
- Source port is 23876
- Destination port is variable, depends on detected client from another source
- Windows 8.1
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.