c++ - boost asio read buffer -


My question is, when you do not know the message size, then what is the best way to read boost TCP socket ? It's a sample I've just put in the size of 10. The code is in different headers, but I did not feel the need to include it all

/////////// HPP

  Typedef boost :: asio :: ip :: tcp :: resolver tresolver; Typedef boost :: asio :: ip :: tcp :: resolver :: query TResolverQuery; Typedef boost :: asio :: ip :: tcp :: endpoint tendpoint; Typedef boost :: asio :: ip :: tcp :: socket Tsocket; Typedef boost :: asio :: ip :: tcp :: acceptor Tacceptor; #Fine for 10th  

//////////// cpp

  while (true) {cout & lt; & Lt; "Recieve" & lt; & Lt; Endl; Promote: shared_ptr & lt; Tapetector & gt; Acceptor (new boost :: asio :: ip :: tcp :: acceptor (* m_io_service)); Boost :: system :: error_code ec; TResolverQuery query (it-> getHost (), boost :: lexical_cast & lt; std :: string & gt; (this- & gt; getPort ()); TResolver resolver (* m_io_service); Formatting endpoint = * resolver Risol (query); Acceptable- & gt; Open (Endpoint. Protocol ()); Acceptor- & gt; Set_option (boost :: asio :: ip :: tcp :: acceptor :: reuse_address (true)); Acceptable- & gt; Dam (end point); Acceptor-> (Listen); Promote: shared_ptr & lt; Tsocket & gt; Soknow (New Tsocket (* m_io_service)); Acceptant- & gt; Accept (* Soknow, End Point); Promotion :: Array & lt; Char, tsize & gt; Buf; Boost :: asio :: read (* socknew, boost :: asio :: buffer (buf), ec); Cout.write (buf.data (), Tsize); Cout & lt; & Lt; Std :: endl; Socknew-> Closed (boost :: asio :: ip :: tcp :: socket :: shutdown_both, ec); Cout & lt; & Lt; "Thread ID" & lt; & Lt; Promote: this_thread :: get_id () & lt; & Lt; Endl; }  

The two most common ways to use the protocol is that message, or at the end Message is the marker.


Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -