0

I am trying to create a Websocket Server on my local machine by doing:

WebSocketServer server = new WebSocketServer("ws://127.0.0.1:5040");

but I am getting the error:

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

even though netstat -an shows that the port 5040 is in the LISTENING state. I have tried running Visual Studio in admin mode, disabled my firewalls etc. but I keep getting the error. Am I supposed to use a port that does not appear when running netstat -an? If not, how do I fix the above error?

Harry Stuart
  • 1,781
  • 2
  • 24
  • 39
  • 1
    possible duplicate: https://stackoverflow.com/questions/10461257/an-attempt-was-made-to-access-a-socket-in-a-way-forbbiden-by-its-access-permissi/10461978#10461978 – jazb Dec 11 '18 at 05:52
  • My situation doesn’t seem to have been solved by this answers – Harry Stuart Dec 11 '18 at 05:53
  • ok, it was worth a try... – jazb Dec 11 '18 at 05:55
  • You say the port is listet as `LISTENING`? In that case you can run `netstat -o` to find out which process is using the port as described in the proposed duplicate question's answer. If the port is already in use by another process, you can't use it and need to use another port. – Streamline Dec 11 '18 at 06:52
  • The port does not appear when running `netstat -o` – Harry Stuart Dec 11 '18 at 06:58
  • You want `netstat -ano`. What operating system are you on? Also, anti-viruses can prevent certain ports from being listened on. – Collin Dauphinee Dec 11 '18 at 07:10
  • Windows 10 and I have no 3rd party anti virus – Harry Stuart Dec 11 '18 at 07:11
  • If you already have 5040 in `LISTENING` state from `netstat -an`, it's already in use by something. You have to pick another port or kill the service that's using it (`-ano` will give you the PID in the last column). I recall one of the Windows services using 5040. – Collin Dauphinee Dec 11 '18 at 07:17
  • I understand now, so how do I choose an appropriate port that isn’t currently occupied? – Harry Stuart Dec 11 '18 at 07:25
  • 1
    Pick a random port (ideally with five digits) and hope that nothing else is using it – Collin Dauphinee Dec 11 '18 at 07:40

0 Answers0