Try making the following edits to your code:
fprintf (stderr, "[Child] Tring to accept...\n");
client_sockfd = accept(server_sockfd, (struct sockaddr*)&client_address, &client_len);
fprintf (stderr, "[Child] done!\n");
and
fprintf (stderr, "[Parent] waiting for child...\n");
pid_child=wait(&stat_val);
fprintf (stderr, "[Parent] done waiting\n");
In the parent, you are waiting for the child to exit while the child is waiting for the connect from the parent to do its work.
L7Sqr
Practically a Master Poster
657 posts since Feb 2011
Reputation Points: 201
Solved Threads: 124
I think the issue here is that the child is failing to accept. Perhaps I have an error in my accept call. Any ideas?
I described the problem. The parent is blocking waiting for the client to exit. The client is blocking waiting for the server to connect. You are in deadlock.
Remove the wait call since the client will never exit without the parent connecting to it. Use some type of IPC to coordinate between the parent and the child so that the parent runsafter the child is in the accept state.
L7Sqr
Practically a Master Poster
657 posts since Feb 2011
Reputation Points: 201
Solved Threads: 124