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