2

We are facing a problem while trying to access Port 80 on a windows 7 machine using C# code.

This error happens to occur only on Windows 7 machine while the same piece of code works fine on a Windows XP machine.

The C# code that we are using makes use of core socket programming. Below is the snippet where we are binding the address to port 80.

public static int rx_Port = 80;

IPEndPoint ip_rx = new IPEndPoint(IPAddress.Any, rx_Port);

If we try to access port 80 then I get an error as

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

I’m double sure that I have given permission to port 80 under all categories to communicate through Firewall.

Even simple client server programs do not work if port 80 is specified on a Windows 7 machine but the same piece of code works fine on an Windows XP machine. I really can't make out what's happening here...

Any thoughts on how to proceed?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Bhairav Gooli
  • 63
  • 2
  • 8
  • 2
    Is Port 80 already in use? (`netstat -a -o > ports.txt` - then scan for 'LISTENING') Are you running any anti-virus or anti-malware software? (eg Norton Internet Security, etc) Have you tried using another port? (eg: 81, 255, 3600) –  Mar 30 '12 at 04:05
  • 2
    If i do netstat -a -o then I see that port 80 is being used by a process whose pid is 4 on a windows 7 machine and it can't be killed. Its a clean system with no antivirus. The program works fine if I specify any other port except 80. – Bhairav Gooli Mar 30 '12 at 04:48
  • 1
    It sounds like you probably have IIS installed - you will need to stop it. –  Mar 30 '12 at 05:21
  • 1
    This question has a bunch of other answers as to what else could be using port 80: http://stackoverflow.com/questions/1430141/port-80-is-being-used-by-system-pid-4-what-is-that –  Mar 30 '12 at 05:36
  • 1
    Only one process at a time can use a specific address/port pair. Also, ports below 1024 are special and may need special permissions to use. – Some programmer dude Mar 30 '12 at 06:15

1 Answers1

2

Kernel-mode HTTP driver HTTP.sys is running.

You can configure it using netsh.

http://msdn.microsoft.com/en-us/library/windows/desktop/cc308384(v=vs.85).aspx

For example to see what IP addresses it is listening on:

netsh http show iplisten

You can then remove them with

netsh http delete iplisten address=1.1.1.1

(for example).

However if you are writing a Windows application I suggest you probably want to cooperate with IIS, rather than just disabling it. If you use a HttpListener you can configure it to share the port with IIS, and it will recieve requests for certain URL prefixes that you specify.

The documentation has a simple example (& have never used this myself).

http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx

You will have to use netsh to give your application user identity permission to the URL prefixes you want to use.

Ben
  • 34,935
  • 6
  • 74
  • 113