I am using Strophe C library for XMPP messaging and libwebsock to create Websocket server.What I want to do is forward the messages recieved on strophe to the Websocket clients and vice versa. However I dont know how to do this.
Also both strophe and libwebsock needs to run event loops to handle events. How can I run both the loops or mege them into one so as to handle the events from both libraries in the same program?
Thanks in advance. :)
First of all you need to create 2 threads. Let thread1 be libstrophe's event loop and thread2 be libwebsock's event loop respectively. General idea can be described with the next pseudo-code:
But (!) since libstrophe is not thread-safe you can't call xmpp_send() from the thread2 directly. Instead, I would recommend to make a queue protected with a mutex. So, the above example transforms to: