Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MSG Handler Example taken from https://github.com/jmossberg/cpp-networking-ts/blob/master/networking-ts-sync.cpp
- static void Vaas_net_msg(string MSG_TYPE,string MSG_DATA,const char* destination){
- net::io_context io_context;
- net::ip::tcp::socket socket(io_context);
- net::ip::tcp::resolver resolver(io_context);
- net::connect(socket,resolver.resolve(destination,"http")); // I'll setup SSL right after I get this function sending msgs and data to the webserver
- // 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?
- 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}){
- 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
- }
- string header;
- net::read(socket,net::dynamic_buffer(header),[&header](auto ec,auto n) -> size_t{ // For the reply back from the webserver?
- if(ec || (header.size() > 3 && header.compare(header.size()-4,4,"\r\n\r\n") == 0))return;
- return;
- }
- );
- std::string body;
- std::error_code e; // the error returned(if any error does occure)
- net::read(socket,net::dynamic_buffer(body),[](auto ec,auto n) -> size_t{ // Or is this the reply back from the web server?
- if(ec)return; //handle errors 1 // weird examples, I'll probably worry about this later
- },e);
- if(e == net::error::eof){ // why does this need 2 error handling sections?
- }else if(e){
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment