boost-asio

UDP bind: Address already in use

落爺英雄遲暮 提交于 2019-12-25 09:14:40
问题 I have no knowledge in node.js . I am sending UDP packets in C++ and I want to show them in node.js . The problem is that both try to occupy the IP/port. Depending on which one I run, the other one fails. How should I fix this problem? main.cpp // g++ main.cpp -o main -std=c++11 -lboost_system -pthread #include <iostream> #include <stdio.h> #include <string> #include <boost/asio.hpp> using boost::asio::ip::udp; int main(int argc, char* argv[]) { const int port=1414; const std::string ip="127

boost::asio::io_service: return control to IO service's run while waiting for future

一笑奈何 提交于 2019-12-25 09:07:43
问题 I have a method that gets called via a third party from IO service. My method is supposed to return a boolean. However, I need to post another task to the same IO service, and wait for it to complete before I know the result. How can I return control to the IO loop while I wait for the other task to finish? (I can add multiple threads, but then there could be multiple calls to my methods, and you'd still end up with a deadlock) Call graph before: <thread> io_service third_party my_stuff | | |

Lost in threads - how can I extend this example correctly?

放肆的年华 提交于 2019-12-25 06:46:04
问题 I am adapting this example to check if a message has taken too long to receive. read_complete is called, when read_start has finished. However, I have to check, if the received data is complete and interpret it as incomplete, if it is not fully received in a given time. These are my extensions to the code above in code/pseudocode: void read_complete(const boost::system::error_code& error, size_t bytes_transferred) { // the asynchronous read operation has now completed or failed and returned

Boost.Asio: Reading input from SSL-Socket results in incomplete data

不羁岁月 提交于 2019-12-25 06:34:40
问题 I have a class called NIUserSession which handles a SSL-encrypted connection with a client. This is it, although I removed everything which is not relevant for my question: typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket; class NIUserSession { public: /*....*/ void readUntil(std::string until); /*....*/ private: /*....*/ void readHandler(const boost::system::error_code& error, std::size_t bytes_transferred); ssl_socket socket_; boost::asio::streambuf readBuffer; /*..

Boost UDP asynchronous client receiving its own datagram

强颜欢笑 提交于 2019-12-25 06:14:17
问题 I am trying to make a simple UDP client/server test using Boost::asio. I've already read the documentation and the official tutorials, but I still couldn't get it right. My problem is specifically on the client side. Here's what I want the client to do: it has to send a simple datagram to the server running at localhost:12345 and then subsequently listen for the response datagram that the server sends. That's not what I am getting, though. Looks like the client is sending the datagram alright

Getting the destination address of UDP packet

坚强是说给别人听的谎言 提交于 2019-12-25 06:12:09
问题 I have been using the following example posted in this same site. This is my version of it. (Please excuse my lack of experience with C socket programming:) In constructor: server::server(io_service& io_service, const int port) : udpsocket_(io_service, udp::endpoint(udp::v4(), port))) { int sock = udpsocket_.native(); fd_set fdset; FD_ZERO(&fdset); FD_SET(sock, &fdset); int opt = 1; setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)); } Where "udpsocket_" is actually a boost asio udp

sending packets to a client given the remote_endpoint object and the socket?

别来无恙 提交于 2019-12-25 04:14:06
问题 Is there a way to send a packet to a client knowing the remote_endpoint object where endpoint.address and endpoint.port are used? EDIT : I added the async_write free function but I still don't know how to specify the ip-address or the port for the socket_ to send data_ to (the client). The changes are lines 44-49 to the boost async server example. #include <cstdlib> #include <iostream> #include <boost/bind.hpp> #include <boost/asio.hpp> using boost::asio::ip::tcp; class session { public:

shared_from_this() is called after object pointing by this is destroyed: C++ ASIO

拜拜、爱过 提交于 2019-12-25 03:12:34
问题 I am tryin to develop ASIO Application and have referred Chat-Server When my CServer Object destructs it causes CSerSessionsManager Object to destruct- which holds shared pointer to all active chat sessions. It causes all active CSerCession Objects to destroy as well. See the Definitions class CServer { CServer(asio::io_service& io_service, const std::string serIdentity, std::string IP, const std::string port); ~CServer(); ..... private: mutable tcp::acceptor acceptor_; // only in the

How to connect signal to boost::asio::io_service when posting work on different thread?

我与影子孤独终老i 提交于 2019-12-25 02:54:00
问题 I'm trying to use a boost::lockfree queue to manage tasks. These tasks retrieve data and would be processed on a worker thread. Once data is retrieved, a signal should be sent to the main thread with the data. The worker thread is spawned at the start of the application and just keeps polling the queue. I'm new to Boost::Asio but from my research, it seems to be the best mechanism for sending signals between threads. I've looked at several examples, in particular: Confused when boost::asio:

ASIO client server shutdown

限于喜欢 提交于 2019-12-25 00:11:06
问题 Please refer to the ASIO examples at : http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/examples/cpp03_examples.html The connection class code is at : http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/example/cpp03/http/server/connection.cpp This class has a stop() function which calls stop on socket that has been created corresponding to a connection request to server (from void server::start_accept()) The client code resides at : http://www.boost.org/doc/libs/1_57_0/doc/html