boost-asio

Websockets using asio c++ library for the server and javascript as client

久未见 提交于 2019-12-01 22:53:16
I have written server code in C++ using the asio library. I know that the server code works, because I tested it with a client also written in C++ and using asio . The problem is that with the following javascript code for client, the connection doesn't get accepted. I immediately see the message box Connection closed... on the javascript client, and on the server I see this strange message: Data RECEIVED: <------ I print this line myself GET / HTTP/1.1 Host: localhost:15562 Connection: Upgrade Pragma: no-cache Cache-Control: no-cache Upgrade: websocket Origin: http://localhost:63344 Sec

Proper cleanup with a suspended coroutine

故事扮演 提交于 2019-12-01 22:21:26
I'm wondering what the best (cleanest, hardest to mess up) method for cleanup is in this situation. void MyClass::do_stuff(boost::asio::yield_context context) { while (running_) { uint32_t data = async_buffer->Read(context); // do other stuff } } Read is a call which asynchronously waits until there is data to be read, then returns that data. If I want to delete this instance of MyClass, how can I make sure I do so properly? Let's say that the asynchronous wait here is performed via a deadline_timer's async_wait. If I cancel the event, I still have to wait for the thread to finish executing

Boost ASIO: Send message to all connected clients

╄→尐↘猪︶ㄣ 提交于 2019-12-01 22:03:28
问题 I'm working on a project that involves a boost::beast websocket/http mixed server, which runs on top of boost::asio . I've heavily based my project off the advanced_server.cpp example source. It works fine, but right now I'm attempting to add a feature that requires the sending of a message to all connected clients. I'm not very familiar with boost::asio , but right now I can't see any way to have something like "broadcast" events (if that's even the correct term). My naive approach would be

Proper cleanup with a suspended coroutine

99封情书 提交于 2019-12-01 21:56:16
问题 I'm wondering what the best (cleanest, hardest to mess up) method for cleanup is in this situation. void MyClass::do_stuff(boost::asio::yield_context context) { while (running_) { uint32_t data = async_buffer->Read(context); // do other stuff } } Read is a call which asynchronously waits until there is data to be read, then returns that data. If I want to delete this instance of MyClass, how can I make sure I do so properly? Let's say that the asynchronous wait here is performed via a

Creating a HTTPS request using Boost Asio and OpenSSL

ⅰ亾dé卋堺 提交于 2019-12-01 21:12:25
I have created a simple HTTP request wherein I am sending GET,POST and PUT requests to the server. Next I want to switch to HTTPS connection using boost asio library, how should I proceed? I have an Executor Class that resolves and connects to the server and a RequestCreator Class that creates the request. sehe I happen to just have posted such a thing in a comment (...): You just connect over ssl. @Milind coliru.stacked-crooked.com/a/9546326fd1def416 So perhaps it is helpful to you. Live On Coliru #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> #include <iostream> int main() { boost:

How to catch strange undefined behaviour in C++ code?

你。 提交于 2019-12-01 20:49:13
问题 I have strange behaviour in server program. In simple example it works fine (I insert traces everywhere, in pion and asio). #include <pion/http/server.hpp> #include <pion/http/response_writer.hpp> #include <pion/http/response_reader.hpp> #include <pion/http/request_writer.hpp> #include <pion/logger.hpp> #include <pion/scheduler.hpp> int main() { pion::single_service_scheduler shed; shed.set_num_threads(1); boost::shared_ptr<pion::http::server> server (new pion::http::server(shed, 5000));

How to use Boost.Asio c++?

白昼怎懂夜的黑 提交于 2019-12-01 20:26:13
I would try to use the library to use socket Boost.Asio c++ on multiple platforms. I downloaded the latest version here: http://sourceforge.net/projects/boost/files/boost/1.46.1/ but now what do I use in my code? I have compile it? include just enough? Can you tell me the steps? Tom How you use it depends on what you want to do, ;-). The documentation is found here: http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio.html You will find lots of examples that should suite your needs. For building, you should note that the library dependancies depend upon whether you are running on windows

How to catch strange undefined behaviour in C++ code?

倖福魔咒の 提交于 2019-12-01 18:40:07
I have strange behaviour in server program. In simple example it works fine (I insert traces everywhere, in pion and asio). #include <pion/http/server.hpp> #include <pion/http/response_writer.hpp> #include <pion/http/response_reader.hpp> #include <pion/http/request_writer.hpp> #include <pion/logger.hpp> #include <pion/scheduler.hpp> int main() { pion::single_service_scheduler shed; shed.set_num_threads(1); boost::shared_ptr<pion::http::server> server (new pion::http::server(shed, 5000)); server->add_resource("/", handlerFunction); server->start(); sleep(5); } output is like this. Construct

boost asio: “host not found (authorative)”

守給你的承諾、 提交于 2019-12-01 18:19:34
问题 I am making a program for school in which two programs communicate with each other. So far I have not been able to connect the two programs. Whenever I try to connect to localhost:8888 or 127.0.0.1:8888, the error "Host not found (authoritative)" occurs. So far my code is this: Connection.cpp Connection::Connection(std::string Arg) { try { tcp::resolver resolver(io_service); cout<<Arg<<endl; tcp::resolver::query query(Arg, "daytime"); tcp::resolver::iterator endpoint_iterator = resolver

Packing struct in Boost Asio buffer

无人久伴 提交于 2019-12-01 17:57:48
问题 I'm looking for a way to send a packet made of a custom data structure through a socket with Boost Asio. At the moment I understand that you can send a string with the standard boost asio buffer (in the method boost::asio::write(..) ). Is it possible to, for example, send the data from a filled in struct to the server or to a client? If yes, how do I need to do that because I can't find documentation about this. 回答1: You can just copy POD objects bitwise. In fact, Asio accepts boost/std array