boost-asio

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

為{幸葍}努か 提交于 2019-12-02 03:22:20
问题 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:

How to link ws2_32 in Clion

左心房为你撑大大i 提交于 2019-12-02 03:21:58
I am using Clion, which uses MinGW and Cmake. When I try to use the standalone asio library I am getting undefined reference to `WSAStartup@8' undefined reference to `WSASetLastError@4' undefined reference to `closesocket@4' ... I believe I have to link the C:/Windows/System32/ws2_32.dll library. I tried adding something like -L C:/Windows/System32 -lws2_32 : set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS} -static -lws2_32") But that didn't help. How can I fix these errors ? The following CMakeLists.txt compiled error-less. Only 1 line is really required: link

What causes a random crash in boost::coroutine?

浪子不回头ぞ 提交于 2019-12-02 03:00:21
I have a multithread application which uses boost::asio and boost::coroutine via its integration in boost::asio . Every thread has its own io_service object. The only shared state between threads are connection pools which are locked with mutex when connection is get or returned from/to the connection pool. When there is not enough connections in the pool I push infinite asio::steady_tiemer in internal structure of the pool and asynchronously waiting on it and I yielding from the couroutine function. When other thread returns connection to the pool it checks whether there is waiting timers, it

boost::asio with no_delay not possible?

[亡魂溺海] 提交于 2019-12-02 02:15:49
What I know... I need to call set_option(tcp::no_delay(true)) before connect() according to https://stackoverflow.com/a/25871250 or it will have no effect. Furthermore, set_option() works only if the socket was opened beforehand according to https://stackoverflow.com/a/12845502 . However, the documentation for async_connect() states that the passed socket will be closed if it is open before handling the connection setup (see async_connect() ). Which means that the approach I chose does not set NO_DELAY correctly (I have tested this on Windows 7 x64 so I can say for sure). if ( socket.is_open()

boost asio post not working , io_service::run exits right after post

一个人想着一个人 提交于 2019-12-02 01:37:33
I am trying to mix boost signals with asio to do a dispatch based handler invocation. when the post method is invoked from a thread the io_service::run exits immediately, the callback handled to post is never invoked, callback is a C++11 lambda routine. I am pasting the code for more analysis. #include<iostream> #include<thread> #include<boost/signals2/signal.hpp> #include<boost/asio.hpp> static boost::asio::io_service svc; static boost::signals2::signal<void(std::string)> textEntered; static void handleInputText(std::string text) { std::cout<<"handleInputText()"<<" text provided: "<<text;

Boost::Asio Async write failed

六眼飞鱼酱① 提交于 2019-12-02 01:30:00
I am porting an application which uses Boost::Asio to an embedded system. I have already cross-compiled boost 1.57.0 binaries for the board using its BSP. To test the libraries working, I ran two http server examples that use synchronized and asynchronized writing respectively. The Sync version runs fine; while the Async one failed at writing. It returned error "Operation canceled". Can anyone point out where I should look for? Thanks. /* * Boost::Asio async example */ #include <iostream> #include <string> #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/smart_ptr.hpp> using

ASIO ip::tcp::iostream and TCP_NODELAY

允我心安 提交于 2019-12-02 00:30:32
How do i set TCP_NODELAY option if i use ip::tcp::iostream? I need a socket for this, but i can't find how to extract it from iostream. use iostream::rdbuf() #include <boost/asio.hpp> int main() { boost::asio::ip::tcp::iostream stream; const boost::asio::ip::tcp::no_delay option( true ); stream.rdbuf()->set_option( option ); } 来源: https://stackoverflow.com/questions/5706641/asio-iptcpiostream-and-tcp-nodelay

Passing around boost::asio::ip::tcp::socket

为君一笑 提交于 2019-12-01 23:51:16
Alright, this is my current code snippet: namespace bai = boost::asio::ip; bai::tcp::socket tcp_connect(std::string hostname, std::string port) { try { boost::asio::io_service io_service; bai::tcp::resolver resolver(io_service); // we now try to get a list of endpoints to the server bai::tcp::resolver::query query(hostname, port); bai::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); bai::tcp::resolver::iterator end; // looking for a successful endpoint connection bai::tcp::socket socket(io_service); boost::system::error_code error = boost::asio::error::host_not_found;

boost::asio ssl linking error

旧城冷巷雨未停 提交于 2019-12-01 23:03:49
问题 I'm using boost version 1.47, visual studio 2010, I downloaded the binaries for windows and linked to the include directory and lib directory from my project preferences. But I still can't use any ssl functionality from boost::asio. This is the site where I downloaded the binaries: http://www.slproweb.com/products/Win32OpenSSL.html I Downloaded: Visual C++ 2008 Redistributables and Win32 OpenSSL v1.0.1 These are the error messages I get: Error 1 error LNK2019: unresolved external symbol _ERR

Deadlock while using boost::asio::deadline_timer in Windows dll

巧了我就是萌 提交于 2019-12-01 22:55:37
问题 I am trying to use Boost-Deadlinetimer inside a DLL, which is loaded using boost::dll::shared_library. Following code-snippets are reduced to the essentials. Example.h: #include <boost/asio.hpp> class Example { public: Class() : m_timer(m_ioService) { } virtual ~Class() { } //... private: boost::asio::io_service m_ioService; boost::asio::deadline_timer m_timer; //... }; Example.cpp: #include "Example.h" #include <boost/config.hpp> //... extern "C" BOOST_SYMBOL_EXPORT Example MyExample;