parent
e0aa54ea89
commit
96fedc35eb
@ -0,0 +1,97 @@ |
||||
#define OLC_PGE_APPLICATION |
||||
#include "olcPixelGameEngine.h" |
||||
#ifdef _WIN32 |
||||
#define _WIN32_WINNT 0x0A00 |
||||
#endif |
||||
#define ASIO_STANDALONE |
||||
#include <asio.hpp> |
||||
#include <asio/ts/buffer.hpp> |
||||
#include <asio/ts/internet.hpp> |
||||
|
||||
using namespace olc; |
||||
|
||||
std::vector<char>vBuffer(1*1024); |
||||
|
||||
void GrabSomeData(asio::ip::tcp::socket&socket){ |
||||
socket.async_read_some(asio::buffer(vBuffer.data(),vBuffer.size()),[&](std::error_code ec,std::size_t length){ |
||||
if(!ec){ |
||||
std::cout<<"\n\nRead "<<length<<" bytes\n\n"; |
||||
for(int i=0;i<length;i++){ |
||||
std::cout<<vBuffer[i]; |
||||
} |
||||
|
||||
GrabSomeData(socket); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
class SigMMO : public olc::PixelGameEngine |
||||
{ |
||||
|
||||
public: |
||||
SigMMO() |
||||
{ |
||||
sAppName = "SigMMO"; |
||||
} |
||||
|
||||
public: |
||||
bool OnUserCreate() override |
||||
{ |
||||
// Called once at the start, so create things here
|
||||
asio::error_code ec; |
||||
asio::io_context context; |
||||
|
||||
asio::io_context::work idleWork(context); |
||||
|
||||
std::thread thrContext = std::thread([&](){context.run();}); |
||||
|
||||
asio::ip::tcp::endpoint endpoint(asio::ip::make_address("51.38.81.49",ec),80); |
||||
|
||||
asio::ip::tcp::socket socket(context); |
||||
socket.connect(endpoint,ec); |
||||
|
||||
if(!ec){ |
||||
std::cout<<"Connected!"<<std::endl; |
||||
} else { |
||||
std::cout<<"Failed to connect to address:\n"<<ec.message()<<std::endl; |
||||
} |
||||
|
||||
if (socket.is_open()){ |
||||
|
||||
GrabSomeData(socket); |
||||
|
||||
std::string sRequest= |
||||
"GET /index.html HTTP/1.1\r\n" |
||||
"Host: exmaple.com\r\n" |
||||
"Connection: close\r\n\r\n"; |
||||
|
||||
socket.write_some(asio::buffer(sRequest.data(),sRequest.size()),ec); |
||||
|
||||
using namespace std::chrono_literals; |
||||
std::this_thread::sleep_for(20000ms); |
||||
context.stop(); |
||||
if(thrContext.joinable())thrContext.join(); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override |
||||
{ |
||||
// called once per frame
|
||||
for (int x = 0; x < ScreenWidth(); x++) |
||||
for (int y = 0; y < ScreenHeight(); y++) |
||||
Draw(x, y, olc::Pixel(rand() % 255, rand() % 255, rand()% 255));
|
||||
return true; |
||||
} |
||||
}; |
||||
|
||||
|
||||
int main() |
||||
{ |
||||
SigMMO demo; |
||||
if (demo.Construct(256, 240, 4, 4)) |
||||
demo.Start(); |
||||
|
||||
return 0; |
||||
} |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue