Socket send () stuck in C

I am trying to connect two machines, say, machines A and B. I am trying to send a TCP message from A to B (one way). In a normal scenario, this works fine. When the connection is smooth, if the socket in B is closed, send () from A is stuck forever. And that puts the process in a Zombie state. I have a socket in locked mode in machine A. Below is the code that stuck forever.

if (send (txSock,&txSockbuf,sizeof(sockstruct),0) == -1) { printf ("Error in sending the socket Data\n"); } else { printf ("The SENT String is %s \n",sock_buf); } 

How do I know if another socket is closed? What sends a return if the target socket is closed? Will the choice be useful.

+4
source share
1 answer

A process in the zombie state means that it has already exited, but its parent has not yet read its return code. It is likely that your process receives a SIGPIPE signal (this is what you get by default when writing to a private socket), your program has already completed, but the state of the zombie has not yet been resolved.

This related question gives more information about SIGPIPE and how to handle it: SIGPIPE, Broken pipe

+7
source

All Articles