boost-asio

Boost asio, single TCP server, many clients

谁都会走 提交于 2019-11-30 16:21:59
I am creating a TCP server that will use boost asio which will accept connections from many clients, receive data, and send confirmations. The thing is that I want to be able to accept all the clients but I want to work only with one at a time. I want all the other transactions to be kept in a queue. Example: Client1 connects Client2 connects Client1 sends data and asks for reply Client2 sends data and asks for reply Client2's request is put into queue Client1's data is read, server replies, end of transaction Client2's request is taken from the queue, server reads data, replies end of

Boost asio, single TCP server, many clients

随声附和 提交于 2019-11-30 16:11:07
问题 I am creating a TCP server that will use boost asio which will accept connections from many clients, receive data, and send confirmations. The thing is that I want to be able to accept all the clients but I want to work only with one at a time. I want all the other transactions to be kept in a queue. Example: Client1 connects Client2 connects Client1 sends data and asks for reply Client2 sends data and asks for reply Client2's request is put into queue Client1's data is read, server replies,

Use std::mutex for a thread pool managed by boost::asio

若如初见. 提交于 2019-11-30 15:56:00
Somehow a followup of this question . I am only wondering if it is ok to use a std::mutex in functions handeled by a boost::asio:io_service ? Usage of strands is somwhat unpractical. From what I found in the boost reference I would say it is ok. Since it states that Asynchronous completion handlers will only be called from threads that are currently calling io_service::run(). So other threads created by boost should not interfere. Did I get it right? Yes, using a std::mutex inside of a handler is perfectly fine. A strand is just a queue with a mutex in disguise after all. As others have noted,

Boost::Asio, SSL Connection Problems

时光总嘲笑我的痴心妄想 提交于 2019-11-30 15:36:18
I tried to solve my Problem for a few days now and just can't get behind it. I try to do an SSL Connection with the Boost::Asio Library and OpenSSL. There is an Example Code, how to do this: http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/example/cpp03/ssl/client.cpp It builds and runs fine and even the verifying seems to work, but when I send a simple request, nothing happens for quite a long time, and then i get an error Message: "Read Failed: short read". I guess, I'm just doing the request line itself wrong, but i can't figure out how it has to be. I tried both the following lines

boost asio timeout [duplicate]

久未见 提交于 2019-11-30 15:32:47
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to set a timeout on blocking sockets in boost asio? I read some of the entries before about the timeout but I don't understand. I want a defined timeout for the connection. the connect code looks like: try{ boost::asio::ip::tcp::resolver resolver(m_ioService); boost::asio::ip::tcp::resolver::query query(link.get_host(), link.get_scheme()); boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver

boost asio timeout [duplicate]

爱⌒轻易说出口 提交于 2019-11-30 14:47:06
Possible Duplicate: How to set a timeout on blocking sockets in boost asio? I read some of the entries before about the timeout but I don't understand. I want a defined timeout for the connection. the connect code looks like: try{ boost::asio::ip::tcp::resolver resolver(m_ioService); boost::asio::ip::tcp::resolver::query query(link.get_host(), link.get_scheme()); boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); boost::asio::ip::tcp::resolver::iterator end; boost::system::error_code error = boost::asio::error::host_not_found; while (error && endpoint

BOOST ASIO POST HTTP REQUEST — headers and body

天大地大妈咪最大 提交于 2019-11-30 14:08:50
I've been trying to get this to work for a couple of days however I keep getting a 400 error from the server. Basically, what I'm trying to do is send a http POST request to a server that requires a JSON request body with a couple of properties. These are the libs I'm currently using UPDATED --- 7/23/13 10:00am just noticed I'm using TCP instead of HTTP not sure how much this will effect an HTTP call but i can't find any examples of clients using pure HTTP with BOOST::ASIO #include <iostream> #include <istream> #include <ostream> #include <string> #include <boost/asio.hpp> #include <sstream>

Asynchronously waiting until a socket is available for reading/writing in Asio

雨燕双飞 提交于 2019-11-30 13:23:25
I want to do the following with Boost Asio. I have a socket and I want to register a callback to be called when data is available for reading/writing on the socket, but I don't want it to actually do the reading/writing. Basically, what I need is similar to async_read_some / async_write_some , except that the actual reading and writing is not done. I need this because I'm using an external library with its own read and write function that require a socket descriptor as an input parameter and I want to use this library in an asynchronous way. You are looking for reactor-style operations. These

Boost::asio winsock and winsock 2 compatibility issue

三世轮回 提交于 2019-11-30 12:50:31
问题 My project uses windows.h in which winsock.h is used, and I need to include boost:assio which uses winsock2. So I get many errors that says Winsock.h already included. I can define WIN32_LEAN_AND_MEAN. so that windows.h wouldn't use winsock. The problem is , that I need windows.h to use it, and I just need Asio for asynchronous timers. I don't need its winsock2.h . I tried searching how to disable its winsock2 use, and I found that I could do that by defining BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN

Using SSL sockets and non-SSL sockets simultaneously in Boost.Asio?

烂漫一生 提交于 2019-11-30 11:01:09
问题 I'm in the process of converting a library to Boost.Asio (which has worked very well so far), but I've hit something of a stumbling block with regards to a design decision. Boost.Asio provides support for SSL, but a boost::asio::ssl::stream<boost::asio::ip::tcp::socket> type must be used for the socket. My library has the option of connecting to SSL servers or connecting normally, so I've made a class with two sockets like this: class client : public boost::enable_shared_from_this<client> {