0

Hii All,
While running a socket programme (server side ) am getting message like

Address already in use

Am trying to connect to port 80 since port 80 is reserved for https application So before running server side programme i am closing all application that uses https application ,is it enough... or am doing it wrong??

Am trying to make a communication between browser and termial...

Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199

2 Answers2

1

You must run your application as super user(root) on Linux or administrator privileges on Windows in order to bind to port 80. This is the case for all service ports, which is < 1024. Either that or there still is another program binded to that port.

Try using netstat to find out what programs might be listening on port 80.

Example:

on Linux:

netstat -punta

on Windows:

netstat -ban

Both must be run with super user/admin privileges in order to see the program names that bind to specific ports.

Shinnok
  • 6,279
  • 6
  • 31
  • 44
  • what am doing is i run server side progrmme and i get the message TCPServer Waiting for client on port 80 , now i want as soon as i open browser connection is set between terminal and browser and i would send html code to browser .. is it possible ?? , – Amit Singh Tomar Feb 07 '11 at 11:09
0

If you just closed another process listening on 80 port, this port will be blocked for a certain timespan depending on your OS. This behavior is here to prevent an attacker to crash a service on your machine and immediately restart a malicious service on the same port.

This behavior can be disabled by using SO_REUSEADDR (by using setsockopt).

If your main problem is to communicate from a custom server to your broswer, you can use any port in your server for providing HTTP (8080 is common for that), just specify the port in the url http://server:port/ (ie. http://localhost:8080/)

Nekresh
  • 2,948
  • 23
  • 28
  • Thanks Nekresh i will try using some else port and one more thing this port blocked behavior is confirmed?? – Amit Singh Tomar Feb 07 '11 at 11:02
  • I have seem this behavior on Windows, MacOSX, Linux, Net/FreeBSD, ... It the server previously using the port doesn't define the SO_REUSEADDR, the port will remain blocked for a certain amount of time (depending of the OS, depending of the configuration, ...) – Nekresh Feb 07 '11 at 11:06
  • -1, your explanation about preventing an attack is very much incorrect. – Hasturkun Feb 07 '11 at 11:14
  • 1
    http://stackoverflow.com/questions/775638/using-so-reuseaddr-what-happens-to-previously-open-socket – Shinnok Feb 07 '11 at 11:24