parent
							
								
									8195ab166b
								
							
						
					
					
						commit
						7a0ef3aca8
					
				
				 3 changed files with 35 additions and 34 deletions
			
			
		@ -1,28 +1,26 @@ | 
				
			||||
#include <iostream> | 
				
			||||
#include <string> | 
				
			||||
#include "../commun.h" | 
				
			||||
 | 
				
			||||
#include "bakanet.h" | 
				
			||||
using namespace Bk::Net; | 
				
			||||
 | 
				
			||||
int main() | 
				
			||||
{ | 
				
			||||
    log(dns_lookup("edus2.rpn.ch", IpVersion::IPv4)[0]) | 
				
			||||
 | 
				
			||||
    IpAddress ip("127.0.0.1"); | 
				
			||||
    Socket sock(ip, 8080, IpProtocol::TCP); | 
				
			||||
    Socket sock(ip, 9000, IpProtocol::TCP); | 
				
			||||
 | 
				
			||||
    bool status = sock.conn(); | 
				
			||||
    if(!status) perror("Couldn't connect."); | 
				
			||||
    if(!sock.conn()) { | 
				
			||||
        perror("Couldn't connect to the end point."); | 
				
			||||
        exit(1); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    std::string msg = "GET / HTTP/1.1\r\n"; | 
				
			||||
    std::vector<char> data(msg.begin(), msg.end()); | 
				
			||||
    Packet packet, meta; | 
				
			||||
    std::string str("Hello world"); | 
				
			||||
    
 | 
				
			||||
    sock.write(data); | 
				
			||||
    packet.push<char>(str.c_str(), str.length()); | 
				
			||||
    meta.push<int>(packet.size()); | 
				
			||||
 | 
				
			||||
    std::vector<char> r_data; | 
				
			||||
    while((r_data = sock.recv(1024)).size()) | 
				
			||||
    { | 
				
			||||
        log(r_data.size()) | 
				
			||||
        std::string data_to_str(r_data.begin(), r_data.end()); | 
				
			||||
        log(data_to_str) | 
				
			||||
    } | 
				
			||||
    sock.write(meta.payload); | 
				
			||||
    sock.write(packet.payload); | 
				
			||||
    return 0; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,8 @@ | 
				
			||||
#pragma once | 
				
			||||
 | 
				
			||||
#include <iostream> | 
				
			||||
#include <vector> | 
				
			||||
#include <string> | 
				
			||||
#include <bakanet.h> | 
				
			||||
 | 
				
			||||
#define log(str) std::cout << str << "\n"; | 
				
			||||
					Loading…
					
					
				
		Reference in New Issue