I am required to implement a websocket server on C++ code running on Linux. At times, I also need to push data asynchronously to client.
So far, I have tried beast echo server, libwebsocket test server and libonion (It would crash once attempted to connect from a browser with error "Cant calculate SHA1 if gnutls is not compiled in! Aborting now". But, I haven't been able to come up with anything that I can build upon.
Below I am trying to provide more information by dummy test class.
test.cpp
class test
{
public:
void processDataFromClient(const string & data);//this needs to get filled by websocket read method? how?
void pushDataToClient(const string & data);
};
test::pushDataToClient(const string & data)
{
(socketId, text) // how do I call this from my test.cpp ?
}
test::void processDataFromClient(const string & data)
{
//do some computation based on the text received
//turn on the light
//once Light is on for a minute call
pushDataToClient( lighton) ;
}
//websocket_server.cpp
main
{
//open a webSocket
//listen for messages from client i.e pass data received from onion_websocket_read to test class by calling processDataFromClient();
//send asynchronous messages to client received from test class. i.e. pushDataToClient should invoke onion_websocket_write //do we need a thread for this ? how to achieve this?
}
I am looking for a simple interface that would allow me to start a websocket, receive and send data to/from client asynchronously.