Linux Error: bind error: Address already in use [How to Solve]

About network programming, the server-client bind error: address already in use:

reason:

1. You used the port number, but the process did not exist.

2. At the end of the process:

crtl +c   And crtl + Z are different. The former ends the process and the latter suspends the process

If you use the latter, the process will hang and not be killed

 

Solution:

1. Kill the process

PS – Aue view PID   , Then kill + process PID and kill the process

2. Change the port number

3. Wait half a minute until the port is released

4. External parameter transmission

It is more convenient to directly change the new port number than 2

5. Use the setsockopt() function to cancel the port number binding restriction

int on=1;
setsockopt(fd,SOL_ SOCKET,SO_ REUSEADDR,& on,sizeof(on));


Read More: