c - Error: Address already in use while binding socket with address but the port number is shown free by `netstat` -


i tried bind socket(server socket) @ port number 8000. worked , did job me. @ end of code close socket well. next instant run code again , shows me address in use. have printed meaning of error values strerror(errno); see if code working @ each point. check if port free checked using netstat shows port number 8000 free. has happened me lot of times. every time wait few more secs , starts working again. using c language. reason behavior os.

after few more secs run code , works.

anirudh@anirudh-aspire-5920:~/desktop/testing$ sudo ./a.out  socket creation: success file open: success socket bind: address in use socket listen: address in use ^c anirudh@anirudh-aspire-5920:~/desktop/testing$ sudo netstat -lntp active internet connections (only servers) proto recv-q send-q local address           foreign address         state       pid/program name tcp        0      0 0.0.0.0:80              0.0.0.0:*               listen      1348/lighttpd    tcp        0      0 0.0.0.0:22              0.0.0.0:*               listen      984/sshd         tcp        0      0 127.0.0.1:631           0.0.0.0:*               listen      1131/cupsd       tcp        0      0 0.0.0.0:3306            0.0.0.0:*               listen      1211/mysqld      tcp6       0      0 :::22                   :::*                    listen      984/sshd         tcp6       0      0 ::1:631                 :::*                    listen      1131/cupsd       anirudh@anirudh-aspire-5920:~/desktop/testing$ sudo ./a.out  socket creation: success file open: success socket bind: address in use socket listen: address in use ^c anirudh@anirudh-aspire-5920:~/desktop/testing$  

i've run same issue well. it's because you're closing connection socket, not socket itself. socket can enter time_wait state (to ensure data has been transmitted, tcp guarantees delivery if possible) and take 4 minutes release.

or, detailed/technical explanation, check link

it can annoying sure, there's no real way around , it's not bug.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -