Could I read lines from a C++ socket using Ubuntu? -
i wonder if read several lines c++ socket using ubuntu?
please note every line used different purpose (e.g. maybe first used string , second char array).
i.e. put 2 lines directly after each other without encountering problem?
read(socketfiledescriptor, buffer1, buffer_size); read(socketfiledescriptor, buffer2, buffer_size);
thanks in advance, regards,
you call read
twice in sequence without problem in itself.
what each call may not correspond single line of input though. read
"raw" reading, when reading file on disk--if data available, read data necessary fill buffer gave (up size specified).
tcp treats data stream, data pass 2 (or more) separate calls write
end being put single packet , transmitted together. on receiving end, data read single call read
--or, depending on buffer size pass, might read part of one, or might read of first , part of second, etc.
if want read input "lines", (for 1 example) create stream buffer reads data socket, , create iostream object parses data buffer read lines. seems attractive many people (it did me, anyway), has never worked out well, @ least me. iostreams assume synchronous protocol, sockets asynchronous. trying treat sockets synchronous tends lead more problems rather solutions.
Comments
Post a Comment