I'm implementing a simple connection between a client and a server in C. In client side, I'm in a loop, reading from a file; every time BUFFER_SIZE bytes and sending it to the server side (didn't upload error handling).
//client side
bytesNumInput = read(inputFileFD,bufInput,BUFFER_SIZE)
bytesSend = write(sockfd,bufInput,bytesNumInput)
Of course the server is also in a loop.
//server side
bytesRecv = read(sockfd,bufOutput,bytesNumInput)
Now, my questions are:
Can I get EOF in the middle of the connection if the server reads faster than the client?
No. EOF means the peer has disconnected. If the connection is still alive, read()
will block until (a) at least one byte is transferred, (b) EOF occurs, or (c) an error occurs.
Does the read function wait to get all the data or is it the same as reading from a file?
See (a) above.
Is it possible the server will handle 2 read in 1 write iteration?
Yes. TCP is a byte-stream protocol, not a messaging protocol.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.