【发布时间】:2017-06-08 06:05:31
【问题描述】:
我需要在 Linux 上运行的 C++ 代码上实现 websocket 服务器。 有时,我还需要将数据异步推送到客户端。
到目前为止,我已经尝试过野兽回声服务器、libwebsocket 测试服务器和 libonion(一旦尝试从浏览器连接时出现错误,它就会崩溃 “如果未编译 gnutls,则无法计算 SHA1!现在中止”。但是,我还没有想出任何可以建立的东西。
下面我试图通过虚拟测试类提供更多信息。
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?
}
我正在寻找一个简单的接口,它可以让我启动一个 websocket,异步接收和发送数据到客户端/从客户端发送数据。
【问题讨论】:
标签: c++ linux websocket server