[英]How to communicate between websocets using javascript as client and python as web server
I have connected my web server and client its working. 我已连接我的Web服务器和客户端,其工作正常。 Now I want to call variables that's passing from backend and do a counting 现在我想调用从后端传递过来的变量并进行计数
for example: backend python is passing 2 variables called price of an apple and no.of apples I need to count the price of all apples and print it in client side using javascript 例如:后端python正在传递2个变量,分别为一个苹果的价格和一个苹果的价格。我需要计算所有苹果的价格,并使用javascript在客户端打印出来
Any help is appreciated 任何帮助表示赞赏
In my case I have done with this approach, 就我而言,我已经采用了这种方法,
code look like, 代码看起来像
var _wObj = null;
function WSSocket(tObj) {
//basic properties
}
create connection 建立连接
WSSocket.createConnection = function ( tObj ) {
if (!_wObj) {
_wObj = new WSSocket(tObj);
}
return _wObj;
}
connect to server 连接到服务器
WSSocket.prototype.connect = function () {
//connection logic
}
register events 注册事件
WSSocket.prototype.registerEvents = function () {
//registering logic
this.wObj.onmessage = function (event) {
//call your operation method
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.