Is synchronous network communication possible on C -
i new networking concepts in c, , wondering following.
say have client , server.
on client side, have such code:
1. send(connfd, var1, var1size); 2. read(connfd, &x, size1); 3. close(connfd);
the server one receive , one send, e.g.,
1. read(connfd, &var, size); 2. send(connfd, var1, varsize);
my question following. on client side, after client send
-- takes time before data arrives @ server, before server reads it, , sends right?
so not happen after client code runs send
, directly jumps read
, time, server has not yet managed prepare response , send -- read call on client side (line 2), receive nothing. , connection terminate right? (program exit).
is how may happen?
this has nothing c, it's how networking protocols , i/o work.
the answer unless go out of way make i/o non-blocking, send()
, recv()
calls synchronous, i.e. block if necessary, wait available outgoing bandwidth or incoming data.
so case describe typically not happen, connection not terminate.
Comments
Post a Comment