Does it read from a socket or receive EOF?

I implement a simple connection between a client and a server in C. On the client side, I am in a loop, reading from a file; each time BUFFER_SIZE bytes and sending them to the server (do not load 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:

  • Is it possible to get EOF in the middle of a connection if the server is reading faster than the client?
  • Does the read function expect to receive all the data, or is it the same as reading from a file?
  • Is it possible that the server will handle 2 read iterations in 1 write iteration?
+4
source share
2 answers
  • No, the server will wait for incoming data. Sockets provide a flow of control.
  • , , , ,
  • , , .
+2

EOF , , ?

. EOF , . , read() , (a) , (b) EOF (c) .

, , ?

. (a).

, 2 1 ?

. TCP - , .

+1
source

Source: https://habr.com/ru/post/1669512/


All Articles