Sometimes your program process can stuck and trigger error like this:
Couldn’t bind to the port
Ok, we have such check in out sockets C code:
if (bind (socket_desc, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) printf("Couldn't bind to the port\n");
And it return negative value.. How to fix it?
- find which process using this port via cmd:
netstat -ano | findstr :<port number>
For example:
C:\Users\n>netstat -ano | findstr :2000
You will see such message:
TCP 127.0.0.1:2000 0.0.0.0:0 LISTENING 3560
- last number is ID of process. To kill process:
taskkill /pid <process ID> /F
Example:
C:\Users\n>taskkill /pid 3560 /F
SUCCESS: The process with PID 3560 has been terminated.
Enjoy!