C socket - consecutive read/write, what happens? -



C socket - consecutive read/write, what happens? -

in server/client in c, tcp, happens if consecutive read/write in program? possibile, or i've follow construction "client write->server read->server write->client read"?

is possible this? or possible info 3rd write in server received 2nd read in client, , other bad things this?

client.c

write (1) read (2) read (3) read (4)

server.c

read (1) write (2) write (3) write (4)

yes, possible. reads block (by default) until info available read on socket. there's no need seek arrange reads , writes in particular order, programme wait until there read before read() phone call returns.

your code result in this:

server blocks in read() client write()s client blocks in read() server receives data, read() returns server write()s 3 times client receives data, read(1) returns client's read(2) called , returns info arrive client's read(3) called , returns info arrive

on fast link it's possible server write()s , client read()s happen @ same time, maybe interleaved, server write()s in order , client's read()s in order.

data ordering preserved if sockets sock_stream, eg. tcp or unix sockets you're asking about.

so read(2) homecoming info written in write(2) tcp socket.

if used udp socket (sock_dgram's default) might find messages received out-of-order or not @ all.

c sockets tcp

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -