Bind failed: Address already in use

前端 未结 7 2009
慢半拍i
慢半拍i 2020-11-30 21:39

I am attempting to bind a socket to a port below:

if( bind(socket_desc,(struct sockaddr *) &server, sizeof(server)) < 0)
{
    perror(\"bind failed.         


        
7条回答
  •  旧时难觅i
    2020-11-30 21:49

    Address already in use means that the port you are trying to allocate for your current execution is already occupied/allocated to some other process.

    If you are a developer and if you are working on an application which require lots of testing, you might have an instance of your same application running in background (may be you forgot to stop it properly)

    So if you encounter this error, just see which application/process is using the port.

    In linux try using netstat -tulpn. This command will list down a process list with all running processes.

    Check if an application is using your port. If that application or process is another important one then you might want to use another port which is not used by any process/application.

    Anyway you can stop the process which uses your port and let your application take it.

    If you are in linux environment try,

    • Use netstat -tulpn to display the processes
    • kill This will terminate the process

    If you are using windows,

    • Use netstat -a -o -n to check for the port usages
    • Use taskkill /F /PID to kill that process

提交回复
热议问题