I’ve written basic server in C. The source code of the server is something like this:
int sfd; ... read(sfd,...); write(sfd,...); ...
and the client is:
int sfd; ... write(sfd,...); read(sfd,...); ...
What is the order in which those primitives are called? write(client), read(server), write(server), read(client). In this order? If not, is there a way we can ensure that?
writeandreadare blocking. It doesn’t matter which is called first. If you callreadon the server beforewriteon the client, thenreadwill block until receives the appropriate number of bytes.