mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-05 23:36:23 +00:00
wesocket base
This commit is contained in:
@@ -1,43 +1,58 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 11/6/2020
|
||||
///
|
||||
#include <boost/beast/core.hpp>
|
||||
/*#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>*/
|
||||
#include "Security/Enc.h"
|
||||
#include <iostream>
|
||||
#include "Logger.h"
|
||||
#include <thread>
|
||||
#include <string>
|
||||
|
||||
namespace beast = boost::beast;
|
||||
/*namespace beast = boost::beast;
|
||||
namespace http = beast::http;
|
||||
namespace websocket = beast::websocket;
|
||||
namespace net = boost::asio;
|
||||
using tcp = boost::asio::ip::tcp;
|
||||
//ws.write(asio::buffer("Hello, world!"));
|
||||
// asio::connect(sock,r.resolve(asio::ip::tcp::resolver::query{host, "80"}));
|
||||
// beast::websocket::stream<asio::ip::tcp::socket&> ws(sock);
|
||||
// ws.handshake(host,"/");
|
||||
|
||||
std::string GetRes(const beast::flat_buffer& buff) {
|
||||
return (char*)buff.data().data();
|
||||
}*/
|
||||
|
||||
void SyncData(){
|
||||
DebugPrintTID();
|
||||
using namespace boost;
|
||||
std::string const host = "95.216.35.232";
|
||||
net::io_context ioc;
|
||||
/*DebugPrintTID();
|
||||
try {
|
||||
std::string const host = Sec("95.216.35.232");
|
||||
|
||||
tcp::resolver r(ioc);
|
||||
net::io_context ioc;
|
||||
tcp::resolver r(ioc);
|
||||
|
||||
websocket::stream<tcp::socket> ws{ioc};
|
||||
auto const results = r.resolve(host, "3600");
|
||||
net::connect(ws.next_layer(), results.begin(), results.end());
|
||||
websocket::stream<tcp::socket> ws(ioc);
|
||||
auto const results = r.resolve(host, Sec("3600"));
|
||||
net::connect(ws.next_layer(), results.begin(), results.end());
|
||||
|
||||
|
||||
ws.handshake(host, "/");
|
||||
beast::flat_buffer buffer;
|
||||
ws.write(boost::asio::buffer("Hello, world!"));
|
||||
ws.read(buffer);
|
||||
|
||||
std::cout << GetRes(buffer) << std::endl;
|
||||
|
||||
ws.close(websocket::close_code::normal);
|
||||
|
||||
}catch(std::exception const& e){
|
||||
error(e.what());
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
exit(0);
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void WebsocketInit(){
|
||||
std::thread t1(SyncData);
|
||||
t1.detach();
|
||||
/*std::thread t1(SyncData);
|
||||
t1.detach();*/
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user