通过Web套接字在JavaScript和C ++代码之间的通信? [英] communication between javascript and C++ code through web sockets?

查看:160
本文介绍了通过Web套接字在JavaScript和C ++代码之间的通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在Ubuntu(Linux)上运行的javascript(客户端 - 通过node.js执行)和C ++(服务器)代码,我想让这个客户端 - 服务器相互通信。有人可以告诉我如何使C ++代码像服务器或客户端使用Web套接字工作?基本上,我想让javascript代码发送一些数据到C ++代码,C ++代码将处理数据,并将结果返回到JavaScript代码。我不知道如果我这种javascript和C ++代码之间的通信可以发生与出口的Web套接字。



谢谢,
pats

解决方案

你有几个选择。我假设你的C ++服务器已经有一个websocket服务器上运行,但如果没有,获取Mongoose或非GPL fork Civetweb。这两个都是微小的c代码,你在你的C ++程序中添加webserver,包括websockets,功能。



事实上,civetweb有一个websocket的例子。 >

然而,你不需要一个websocket,只是一个普通的socket应该做。您可能希望以JSON格式发送数据,以便javascript代码易于使用。


I have javascript (client - executed through node.js) and C++ (server) code running on Ubuntu (Linux) and I want this client-server to communicate with each other. Can somebody tell me how I can make C++ code work like a server or client using web socket? Basically, I want javascript code to send some data to C++ code, the C++ code will process on the data and return the result back to javascript code. I'm not sure if I this communication between javascript and C++ code can happen with out web socket. Any pointers in this direction would be of great help!

Thanks, pats

解决方案

You have several choices. I am assuming your C++ server already has a websocket server running on it but if not, get Mongoose or the non-GPL fork Civetweb. Both are tiny bits of c code you build into your C++ program to add webserver,including websockets, functionality.

In fact, civetweb comes with a websocket example.

However, you do not need a websocket, just an ordinary socket should do. You'll probably want to send the data in JSON format to makeit easy to consume by the javascript code.

这篇关于通过Web套接字在JavaScript和C ++代码之间的通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆