Hi, fairly new to linux and C. I am trying to write a c program to communicate through a socket. I have been trying to do it by just reading the man pages. When I went to test it, server.c failed here:
Code:
if((foreign_sockfd = accept(local_sockfd,(struct sockaddr *) &addr, (socklen_t *) sizeof(addr))) == -1){
perror("Accept failed");
exit(1);
}
It failed due to one of the arguments in the accept function being incorrect which I have now fixed. But my problem is the socket did not close out correctly.
I'm guessing I should have used close() before the exit(1). Now when I try to run the program again I get "Address already in use" I did a search on this forum and did not see anything about this. I also google'd it and got several suggestions. None of the suggestions worked, and I don't see anything in the man pages unless I am looking in the wrong place. I have read about a TIME_WAIT status to make sure all tcp packets were transferred. I had one TIME_WAIT. Now I only see close_waits After a google search i tried restarting the networking service. I have tried unlink(socketpath). It's several hours later and it still won't run. Is there another way to force a close on a socket? netstat -ntp returns the following
tcp 1 0 192.168.1.126:41933 x.x.x.x:80 CLOSE_WAIT 1939/ubunt
tcp 1 0 192.168.1.126:50336 x.x.x.x:80 CLOSE_WAIT 2101/python
I'm not sure which one, if any, is the cause of this. I am using AF_UNIX option, so this is all on the same pc. After searching on how to force close_wait file descriptor, the only solutions I see refer to looking for software bugs in the application that caused the problem. However, I am the one that caused the problem with my newb programming skills :[ Any help is greatly appreciated. God Bless.