Guest User

Untitled

a guest
Mar 13th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. // MSG Handler Example taken from https://github.com/jmossberg/cpp-networking-ts/blob/master/networking-ts-sync.cpp
  2. static void Vaas_net_msg(string MSG_TYPE,string MSG_DATA,const char* destination){
  3.     net::io_context io_context;
  4.     net::ip::tcp::socket socket(io_context);
  5.     net::ip::tcp::resolver resolver(io_context);
  6.  
  7.     net::connect(socket,resolver.resolve(destination,"http")); // I'll setup SSL right after I get this function sending msgs and data to the webserver
  8.     // Is this the section for what I'm SENDING to the webserver? also need to figure out what to do with the "Host: ipecho.net" thing later. do I even need that tho?
  9.     for(auto v:{"GET /plain HTTP/1.0\r\n"s,"Host: ipecho.net\n\n"s,"Accept: */*\r\n"s,"Connection: close\r\n\r\n"s}){
  10.         net::write(socket,net::buffer(v)); // 99% sure(?) this is the data that I'm sending to the server but the for loop expression is just really weird looking
  11.     }
  12.  
  13.     string header;
  14.     net::read(socket,net::dynamic_buffer(header),[&header](auto ec,auto n) -> size_t{ // For the reply back from the webserver?
  15.             if(ec || (header.size() > 3 && header.compare(header.size()-4,4,"\r\n\r\n") == 0))return;
  16.             return;
  17.         }
  18.     );
  19.  
  20.     std::string body;
  21.     std::error_code e; // the error returned(if any error does occure)
  22.     net::read(socket,net::dynamic_buffer(body),[](auto ec,auto n) -> size_t{ // Or is this the reply back from the web server?
  23.         if(ec)return; //handle errors 1 // weird examples, I'll probably worry about this later
  24.     },e);
  25.  
  26.     if(e == net::error::eof){ // why does this need 2 error handling sections?
  27.     }else if(e){
  28.     }
  29.     return;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment