search

Home  >  Q&A  >  body text

c++ - I don’t know how much data the server returns. How does PHP’s socket_read() receive the complete data?

If the data sent by the server always exceeds the maximum number of bytes that the client can bear at one time, how can the client determine that the received data is complete without performing the socket_read operation? How much data does the server return? Composed of /n. I tried using a while loop to read the server's data, but there was a problem with the operation.

淡淡烟草味淡淡烟草味2823 days ago656

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 13:11:13

    If it is a short link, use socket_set_nonblock to set the socket link to non-blocking, and then execute socket_read in a loop. When the return value length is 0, jump out of the loop and the reception ends (this method may cause problems in some cases).

    It is best to specify the data length on the server side so that there will be no errors.

    reply
    0
  • Cancelreply