codeplea/Hands-On-Network-Programming-with-C

Chap02 - Time Server Bind failing

Closed this issue · 2 comments

When I compile and run the code for time_server.c I get the following:

bind() failed. (98)
Configuring local address...
Creating socket...
Binding socket to local address...
[Finished in 0.0s with exit code 1]
[shell_cmd: gcc "/home/chuck/ContEd/HOCN/SampleCode/chap02/time_server.c" -o "/home/chuck/ContEd/HOCN/SampleCode/chap02/time_server" && "/home/chuck/ContEd/HOCN/SampleCode/chap02/time_server"]
[dir: /home/chuck/ContEd/HOCN/SampleCode/chap02]
[path: /home/chuck/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]

Hi,

When bind fails with error 98, it means that your local port is already in use (by another application).

Look at line 83:

getaddrinfo(0, "8080", &hints, &bind_address);

Try chaining "8080" to another port number. Alternatively, you can find the other program on your system that is using port 8080 and close it.

Please let me know if this resolves your problem.

Hi,

Yes, I figured that out this morning. I managed to get the socket closed by typing:

sudo netstat -anp | grep 8080

which displayed the pid for the process. I killed the process with:

sudo kill -3 pid

to close the socket and was back on track. I'm not sure how one would do that under Windows though as that is not my primary operating system expertise.