Поделиться через


How to fix the error "port is currently used by another application"

I bet you may have seen this error at least once If you are a web developer  :)

Different error from different tools

IIS manager gives

 ---------------------------
Internet Information Services (IIS) Manager
---------------------------
This Web site cannot be started. Another Web site may be using the same port.

Apache gives

 Apache port:443 is being used by another application.

Visual Studio

 Port 10360 is already being used by another application

So how can we fix this error.There are two parts for this error.

  1. To find out which program uses this port
  2. Does this program really needs to use this port or some other ?

GUI tool approach: Find the processs using port TCPView tool.

You can use tcpview tool from sys internals. This shows all the connections active in the system with which process is using it .

tcpview showing ports used by process

 

You can also easily close the connection forcefully and make the port free just by right clicking on a particular connection.

close a connection opened by a process

 

In the above example, am going to close the connection opened by postgres on port 5432.This can be the port you are looking at where you got the error.

command line approach: Finding out which program uses this port using netstat command.

We combine the output of netstat with find command. We are filtering the netstat output with find .

 C:\>netstat -ano |find ":80"
 TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4
 TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 4
 TCP 176.6.219.84:51311 176.6.57.55:8080 ESTABLISHED 7584
 TCP 176.6.219.84:51351 176.6.57.55:8080 ESTABLISHED 7584
 TCP 176.6.219.84:51383 176.6.57.55:8080 ESTABLISHED 7584
 TCP 176.6.219.84:51462 176.6.57.55:8080 ESTABLISHED 7584
 TCP 176.6.219.84:58672 176.6.57.55:8080 ESTABLISHED 7584
 TCP [::]:80 [::]:0 LISTENING 4
 TCP [::]:8080 [::]:0 LISTENING 4

 

Interpreting the output,you can see the processid in the last column .In our case we have 4 and 7584.That is the process which is using the port.

 TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4
  • TCP is the protocol we are listening on.

  •  IP:Port combination 0.0.0.0:80 or [::] means all IP address in this machine we are LISTENING  .More details here

  • So process id with 4 is listening on 80 and 8080 and you are seeing 4

     0.0.0.0:80 , 0.0.0.0:8080 , [::]:80 ,[::]:8080
    
    
    

process with 4 is basically system process.

Now to find out the process ,we can run another command tasklist

C:\>tasklist |find "7584"
chrome.exe 7584 Console 1 144,272 K

process 4 represents System process.

C:\>tasklist|find " 4 "
System 4 Services 0 308 K

Now you know the process,you can go and verify it really needs to use this port or not

 

  • You can close the connection using TCP view
  • you can stop or kill this particular process. E.g. You have both IIS and Apache installed in one machine and may be some apache website is already using a port you need it.
  • You can reconfigure one process to use another port(e.g. get apache to run under port 8080) or if it is Visual studio,you can go to VS and configure project configuration settings to use another port

Comments

  • Anonymous
    August 27, 2017
    Very helpful and informative article. I am very glad to read this article and this article helps to fix the port using problem by another application. Thanks for sharing such a nice article for beginners link me :)