Open rakshita1006 opened 3 years ago
Please help me with the solution!!!
Please help me with the solution!!!
Heads up: shouting isn't help. Nobody is obliged to solve your issues in any time frame. This is just a free project that you opt to use. I'm not a maintainer here, but I thought I'd let you know.
ON TOPIC: This question was raised on StackOverflow and I analyzed its cause.
The problem is that msghub_impl
does not own the io service, YET insists on starting service threads (even when threads==0
). This causes the service to complete all work before even posting the first async task, and a subsequent run()
(e.g. from main()
) simply has no effect (as per the documentation, the same applies to io_service
in older versions.).
Hi, Thanks for the reply I tried to do all the changes in my code as suggested in above files but still data is not published.
@rakshita1006 can you run the tests? What are you doing different/y? Note also, I have made a fork that has some simplifications in the API. It is still on-the-wire compatible though (until this: https://github.com/sehe/msghub/issues/1)
Hi,
I am not sure what wrong I am doing .I am using Ubuntu 18.0 with boost 1.65.0. I downloaded the code(zipfolder) and created by own clientmain.cpp & servermain.cpp. I included all the relevant header & Library files and compiled the code.The compilation was successful but i am not getting published message.
I also made the necessary changes as suggested by you in fix issue #1,#3 ,#4 and try to run the code.
client code:
using namespace std::chrono_literals;
int main() { boost::asio::io_service io_service; boost::asio::io_service::work work(io_service); { msghub msghub(io_service);
msghub.connect("localhost", 1334);
assert(!io_service.stopped()); // no longer fails due to `work`
msghub.publish("Publish", "new message");
io_service.run_one();
}
io_service.run();
}
Server Code:
void on_message(const std::string& topic, std::vector
int main()
{
boost::asio::io_service io_service;
// Create hub to listen on 0xbee port
msghub msghub(io_service);
msghub.create(1334);
// Subscribe on "any topic"
msghub.subscribe("Publish", on_message);
// Current or any another client
//msghub.publish("Publish", "new message");
io_service.run();
}
Please find the attched file of the output Output server: client:
U ran the code with the same code as here.
Is it the correct way to go or I am missing some step?Does we need to execute code from test folder.if yes then how as there is no main function in that?
Thanks Rakshita
@rakshita1006
What happens when you check out the code from the PR branch and run the tests?
I've added another commit that you can use instead of manually doing the changes: https://github.com/di9it/msghub/pull/7
You can use it from my repo, e.g. in a docker:
docker run --rm -ti ubuntu:20.04
apt update
apt -qqyy install build-essential git cmake libboost-all-dev
git clone https://github.com/sehe/msghub -b cmake
cd msghub
cmake . && make
./examples/server & ./examples/client ; kill %1; wait
The tester has a main function (it's in main.cpp) and depends on Boost Unit Test framework.. is also built by the CMake
Making it even easier, I reduced CMake and Boost requirements to support 18.04 again, and tested with a Dockerfile:
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN \
apt update; \
apt -qqyy install build-essential git cmake libboost-all-dev
RUN git clone https://github.com/sehe/msghub --depth 1 -b cmake
WORKDIR /msghub
RUN cmake . && make
CMD ["/bin/bash", "-c", "(./examples/server & ./examples/client ; kill %1; wait)"]
Put this Dockerfile
somewhere and build it:
docker build . -f containers/issue1 -t msghub:cmake
To do the simple client/server test:
docker run --rm -it msghub:cmake
There are shutdown races impactng the unit tests. I think they're all fixed on my other branch sehe/msghub: https://github.com/sehe/msghub/blob/std-over-boost/containers/std-over-boost
Live demo of the cmake container :
Live demo of the std-over-boost branch which fixes a lot more issues and modernizes the code + interfaces:
@sehe It finally worked for me. Thank you for your help.
Hi,
I am trying to create a pub/sub model using BoostAsio library with the help of your code.
I was able to establish a connection between the publisher and subscriber but the data is neither [published nor subscribe.
Could you please help me with the issue.
Thanks & Regards Rakshita Parihar