if you want to remove an article from website contact us from top.

    an attempt was made to access a socket in a way forbidden by its access permissions

    James

    Guys, does anyone know the answer?

    get an attempt was made to access a socket in a way forbidden by its access permissions from EN Bilgi.

    c#

    private void StartReceivingData(string ipAddress, int iPort) { try { if (!_bContinueReciving) { //initializeMainSocket(ipAddress, iPort);...

    An attempt was made to access a socket in a way forbidden by its access permissions. Why?

    Ask Question

    Asked 10 years, 1 month ago

    Modified 7 months ago

    Viewed 270k times 132

    private void StartReceivingData(string ipAddress, int iPort)

    { try {

    if (!_bContinueReciving)

    {

    //initializeMainSocket(ipAddress, iPort);

    _mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);//<------HERE IS RAISED THE EXCEPTION

    _mSocket.Bind(new IPEndPoint(IPAddress.Parse(ipAddress), iPort));

    // _mSocket.Bind(new IPEndPoint(IPAddress.Loopback, iPort));

    _mSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);

    _mSocket.IOControl(IOControlCode.ReceiveAll, new byte[4] { 1, 0, 0, 0 }, new byte[4] { 0, 0, 0, 0 });

    //var 1

    _mSocket.BeginReceive(_buffReceivedData, 0, _buffReceivedData.Length, SocketFlags.None,

    new AsyncCallback(OnReceive), null);

    initializeLocalSocket();

    } else {

    _bContinueReciving = false;

    _mSocket.Close(); } }

    catch (Exception exception)

    {

    Debug.WriteLine(exception);

    } }

    I don't understand why...it worked and now it doesn't. could someone help me? i am streaming with vlc, and i wan't to receive the packets, do some reports, and then restream local to a player

    c# sockets video streaming Share

    Improve this question

    edited Aug 4, 2021 at 15:33

    moffeltje 4,2744 4 gold badges 29 29 silver badges 52 52 bronze badges

    asked May 5, 2012 at 11:11

    andrew 1,5873 3 gold badges 13 13 silver badges 16 16 bronze badges 2

    If the exception is happening at the CREATE, the I expect you need to be running as Administrator to create RAW sockets. –

    Jesse Chisholm

    Mar 22, 2015 at 21:43

    1

    Highly related, if not duplicate of An attempt was made to access a socket in a way forbidden by its access permissions –

    Robotnik

    Mar 1, 2016 at 14:24

    1

    I have seen a block by the AV with this exception: > 02/01/2017 15:02:18 Blocked by port blocking rule F:\Program > Files\AccessLayers\PortNox\Bin\PortNoxSvc.exe Anti-virus Standard > Protection:Prevent mass mailing worms from sending mail x.x.x.x:25 –

    user7365403

    Jan 2, 2017 at 13:09

    try to test by another port that smaller than 10000 –

    Behzad Ebrahimi

    Nov 4, 2019 at 12:47

    1

    This happened to me when trying to run manually an exe which is a netcore API. It was IIS that holded the port open. –

    Larry

    Mar 24, 2021 at 11:33

    Show 1 more comment

    14 Answers

    225

    I restarted this service : Host Network Service on windows Services program. And it worked.

    You can run these commands in the windows terminal instead, as @admin mentioned in comment section:

    net stop hns net start hns Share Improve this answer

    edited Nov 13, 2021 at 8:12

    answered May 7, 2021 at 22:13

    Parsa 3,4361 1 gold badge 22 22 silver badges 32 32 bronze badges 10

    do you use docker ? I read somewhere that docker is causing this problem –

    Parsa

    May 12, 2021 at 16:03

    3

    Worked for my case –

    Fikri Hailal

    May 20, 2021 at 7:49

    20

    worked for me net stop hns && net start hns –

    admin Jun 9, 2021 at 0:22 3

    @Parsa thanks man!!! really! I used to do a restart for this to work and reset the tcp/ip stack. Yup, I use docker, it's because of docker. Your solution saved a lot of time from me. –

    Mahmoud

    Jun 23, 2021 at 11:46

    6

    When it comes down to Windows restarting things always work :) –

    Eldar

    Jul 17, 2021 at 13:21

    Show 12 more comments

    113

    Most likely the socket is held by some process. Use netstat -o to find which one.

    Share Improve this answer

    answered May 5, 2012 at 12:46

    stark 11.5k3 3 gold badges 32 32 silver badges 48 48 bronze badges 2

    Sysinternals TCPView can be helpful as well for checking if used by another process (as I just ran into) –

    KornMuffin

    Jan 31, 2014 at 19:14

    1

    If the exception were happening at BIND, this would make sense to me. Since it is happening at CREATE, then I expect you need to be Administrator to create RAW sockets. –

    Jesse Chisholm

    Mar 22, 2015 at 21:44

    7

    it's a pity that in my case my app tries to listen on port 62434 BUT checking the listening ports with netstat -o shows that there is not any app currently occupying that port. This is really making me crazy. –

    Hopeless

    Nov 22, 2015 at 19:19

    30

    it's actually netstat -ao that includes ports open for listening, or netstat -ano if you want to save up on DNS lookup, or netstat -ano | find ":80" to filter e.g. by port # 80 –

    Arthur Stankevich

    Sep 25, 2017 at 15:46

    9

    It might also be in an excluded range, check with netsh interface ipv4 show excludedportrange protocol=tcp –

    nexus Feb 7, 2021 at 5:10

    Show 3 more comments

    58

    Reload Visual Studio with Administrator privileges. Windows Sockets (WinSock) will not allow you to create a SocketType.RAW Socket without Local Admin. And remember that your Solution will need elevated privileges to run as expected!

    Source : stackoverflow.com

    Solved

    If you're seeing an error that says "An attempt was made to access a socket in a way forbidden by its access permissions." this may fix it.

    Solved - An attempt was made to access a socket in a way forbidden

    Date Published: 03 November 2020

    I'm assuming you're here because you are seeing this error and are wondering why:

    Microsoft.AspNetCore.Server.Kestrel[0]

    Unable to start Kestrel.

    System.IO.IOException: Failed to bind to address http://localhost:51816.

    ---> System.AggregateException: One or more errors occurred. (An attempt was made to access a socket in a way forbidden by its access permissions.) (An attempt was made to access a socket in a way forbidden by its access permissions.)

    ---> System.Net.Sockets.SocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions.

    at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)

    at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

    at System.Net.Sockets.Socket.Bind(EndPoint localEP)

    at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.g__BindSocket|13_0(<>c__DisplayClass13_0& )

    at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()

    at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)

    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig)

    at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass29_0`1.<g__OnBind|0>d.MoveNext()

    --- End of stack trace from previous location ---

    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)

    at Microsoft.AspNetCore.Server.Kestrel.Core.LocalhostListenOptions.BindAsync(AddressBindContext context)

    --- End of inner exception stack trace ---

    ---> (Inner Exception #1) System.Net.Sockets.SocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions.

    at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)

    at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

    at System.Net.Sockets.Socket.Bind(EndPoint localEP)

    at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.g__BindSocket|13_0(<>c__DisplayClass13_0& )

    at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()

    at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)

    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig)

    at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass29_0`1.<g__OnBind|0>d.MoveNext()

    --- End of stack trace from previous location ---

    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)

    at Microsoft.AspNetCore.Server.Kestrel.Core.LocalhostListenOptions.BindAsync(AddressBindContext context)

    The reason is most likely due to a Windows Update that restricted access to certain ports on Windows machines. The details are here.

    You can view a list of which ports are excluded from your user by running this command:

    netsh interface ipv4 show excludedportrange protocol=tcp

    On my Windows 10 machine I get this output:

    Protocol tcp Port Exclusion Ranges

    Start Port End Port

    ---------- --------

    5357 5357 49800 49899 49900 49999

    50000 50059 *

    50060 50159 50160 50259 50260 50359 50683 50782 50783 50882 50883 50982 50983 51082 51083 51182 51777 51876 51877 51976

    * - Administered port exclusions.

    Specifically, I had an ASP.NET Core web app that previously worked fine with ports 51814 and 51815 but then suddenly wouldn't start. Looking at the list above you can see this is in the range of 51777-51876.

    After changing my ports, everything works again.

    Tags - Browse all tags

    kestrel asp.net core exception

    Category - Browse all categories

    Software Development

    Source : ardalis.com

    How I fixed the error 'an attempt was made to access a socket in a way forbidden by its access permissions' on my machine

    In the last two days i was fighting the werid situation where i couldn’t bind to a specific port on my machine. All the other ports were fine, but this specific one was just blocked and didn’t matter what applicaiton i ran to try to bind to it.

    How I fixed the error 'an attempt was made to access a socket in a way forbidden by its access permissions' on my machine

    Posted Sep 9, 2020 by Tamir Dresher

    In the last two days i was fighting the werid situation where i couldn’t bind to a specific port on my machine. All the other ports were fine, but this specific one was just blocked and didn’t matter what applicaiton i ran to try to bind to it.

    Here are the steps i did until i found the reason:

    make sure it’s not the antivirus or any other security application

    make sure no other process is using this port by running netstat or TCPView

    netstat -ano | wsl grep ""

    if anything shows up, kill the process that owns the port

    kill

    if this didn’t work, reset the machine TCP/IP stack

    netsh int ip reset

    if you find that anything is was blocked and the message “Access is denied” is shown, follow the steps listed here and run the previous step again

    Reset the machine

    This post is licensed under CC BY 4.0 by Tamir Dresher.

    Share

    Source : www.tamirdresher.com

    Do you want to see answer or more ?
    James 15 day ago
    4

    Guys, does anyone know the answer?

    Click For Answer