hey... This is not a problem per se, I am just curious just what I am doing wrong or if is something in the way things work and I dont know it
So I am making a simple server/client using sockets where I use fork on the server to accomodate the client requests. I am just at the beggining but when I tested thing there was somethign I coudnt understand.
So I am entering the server in an endless loop where it acccepts connections from the clients. When a connection is accepted fork() is called and the child takes over. As I understand it the parent goes on to accept new connection. It doesnt wait the child to finish. So i made the child send two messages to the child that prints them and then exit/return...
The thing is when a connection is accpeted i print a message "ACCEPTED". Normally it should print once right, but for some reason it prints then the child printf's and then it prints again and then the parent printf's. Any idea why, Is there something I dont understan in the fork usage??
I have the code in the files...
Also, socket are integer that show to an index table right? So when the child is create we have two copies of the same integer so two copies pointing to the same index/socket. When I close a socket what exactly happens. I know I must close the listening socket in the child process so it wont accept connections as well (like the parent) but what exactly does close does?