0

i need to read data sent from web client.

My code is as follows

size_t len = boost::asio::read_until(*session_sock, response, "\n", ec);

I want to use read_some or read functions, but if i use it is not reading complete data?
Please help,Thanks!

Piyush Gupta
  • 2,181
  • 3
  • 13
  • 28
  • 1
    TCP is a *streaming* protocol, there are not fixed-sized packets, it's all just a stream of data with no fixed beginning or ending (except connection and disconnection). Therefore you need some kind of higher-level protocol above TCP if you want to transmit data that is not a stream, like your JSON structure. A common way is to send the length of the data as a separate header, like the HTTP `Content-length` header field. Or use some kind of data separator or delimiter. Then you need to receive in a loop until you get all the data. – Some programmer dude Feb 15 '16 at 12:38
  • try to find any appropriate for you transport library. Json transport will be simple and powerfull solution for example. It save many time for you. Do not implement this functional yourself. Except when you want to train – oklas Feb 15 '16 at 12:49
  • 1
    See http://stackoverflow.com/questions/24428293/reading-json-from-a-socket-using-boostasio – nos Feb 15 '16 at 12:55
  • @nos Thanks for finding that for me. I remembered posting it. You beat me to it! – sehe Feb 15 '16 at 12:56

0 Answers0