gpt4 book ai didi

C++ Websocket 服务器发起的数据

转载 作者:太空宇宙 更新时间:2023-11-04 06:04:20 25 4
gpt4 key购买 nike

我需要在 Linux 上运行的 C++ 代码上实现一个 websocket 服务器。有时,我还需要异步推送数据到客户端。

到目前为止,我已经尝试过beast echo服务器,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、异步接收数据到客户端或从客户端发送数据。

最佳答案

I am required to implement a server on C++ code running on Linux to support Angular JS client. What are the options available ? Shall I use c++ to implement server over raw socket, boost-asio server, CGI based server support, REST server or is there any better/faster option. I have never implemented this before and unaware of the drawback/advantages of each of the options. I have never coded CGI and REST api before. Let me know your comments.

也许我误解了你的问题,但你是在谈论用 C++ 重写某种基于套接字的 Apache(或 Nodejs)吗? AngularJS 是一个在浏览器中运行的框架。当您说“支持 Angular JS 客户端”时,您的意思是使用 C++ 提供基于 HTML/HTTP 的应用程序吗?这将涵盖其他框架和基于 JavaScript 的实现。

如果这是要求,我不会从头开始这样做。这是一项艰巨的任务。您可以使用并构建一些项目。

这里有一些引用:

https://softwareengineering.stackexchange.com/questions/53624/can-c-be-used-as-a-server-side-web-development-language How to use C++ for apache server

编辑:根据下面的评论,也许是这些解决方案之一?它们是使您能够从 Node/Apache 调用 C++ 程序的模块:

How can I use a C++ library from node.js?
Forwarding apache request to a c++ program

关于C++ Websocket 服务器发起的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41811279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com