Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "wx/wx.h"
- #include <boost/asio.hpp>
- #include <iostream>
- #include <string>
- #include <thread>
- class app_frame :
- public wxFrame
- {
- private:
- wxPanel *panel;
- public:
- app_frame() : wxFrame(0, wxID_ANY, wxT("wxWidgets 3 and boost::asio"), wxPoint(0,0), wxSize(300,600))
- {
- }
- };
- class app :
- public wxApp
- {
- private:
- std::thread worker;
- public:
- virtual bool OnInit()
- {
- worker = std::thread([]() {
- boost::asio::io_service io;
- boost::asio::ip::tcp::socket sock(io);
- boost::asio::ip::tcp::resolver res(io);
- auto end_it = res.resolve({ std::string("localhost"), std::string("5000") });
- std::cout << "Connecting...\n";
- boost::asio::async_connect(sock, end_it, [&](boost::system::error_code ec, boost::asio::ip::tcp::resolver::iterator iter) {
- if (!ec)
- std::cout << "Connected!!!!\n";
- else
- std::cout << "Not connected!!!!\n";
- });
- });
- frame = new app_frame;
- frame->Show();
- return true;
- }
- virtual int OnExit()
- {
- worker.join();
- return 0;
- }
- private:
- app_frame *frame;
- };
- IMPLEMENT_APP(app);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement