How to communicate between websocets using javascript as client and python as web server
I have connected my web server and client its working. 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
Any help is appreciated
javascript python node.js websocket
add a comment |
I have connected my web server and client its working. 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
Any help is appreciated
javascript python node.js websocket
Welcome to Stack Overflow !!! ,,, though not websockets, I think you will find what you are looking for in this post; stackoverflow.com/questions/12232304/…
– SteveJ
Jan 1 at 4:22
Possible duplicate of How to implement server push in Flask framework?
– M.R.Safari
Jan 1 at 7:54
add a comment |
I have connected my web server and client its working. 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
Any help is appreciated
javascript python node.js websocket
I have connected my web server and client its working. 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
Any help is appreciated
javascript python node.js websocket
javascript python node.js websocket
asked Jan 1 at 3:49
Emma ScarletEmma Scarlet
33
33
Welcome to Stack Overflow !!! ,,, though not websockets, I think you will find what you are looking for in this post; stackoverflow.com/questions/12232304/…
– SteveJ
Jan 1 at 4:22
Possible duplicate of How to implement server push in Flask framework?
– M.R.Safari
Jan 1 at 7:54
add a comment |
Welcome to Stack Overflow !!! ,,, though not websockets, I think you will find what you are looking for in this post; stackoverflow.com/questions/12232304/…
– SteveJ
Jan 1 at 4:22
Possible duplicate of How to implement server push in Flask framework?
– M.R.Safari
Jan 1 at 7:54
Welcome to Stack Overflow !!! ,,, though not websockets, I think you will find what you are looking for in this post; stackoverflow.com/questions/12232304/…
– SteveJ
Jan 1 at 4:22
Welcome to Stack Overflow !!! ,,, though not websockets, I think you will find what you are looking for in this post; stackoverflow.com/questions/12232304/…
– SteveJ
Jan 1 at 4:22
Possible duplicate of How to implement server push in Flask framework?
– M.R.Safari
Jan 1 at 7:54
Possible duplicate of How to implement server push in Flask framework?
– M.R.Safari
Jan 1 at 7:54
add a comment |
1 Answer
1
active
oldest
votes
In my case I have done with this approach,
- I have created one JS file for WebSocket event handling methods(onOpen,onClose and onMessage) which is loaded on home page loading.
- In this file I have created one reference variable to hold events of WebSockets using (.prototype)
- Same like second step created two seperate methods for creating connection which is going to be called from home page and one connect method to connect the server
- In onMessage you can call your business method where you can put your logic
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
}
}
Thanks a lot helped a lot to get an idea. I'll try this out and accept
– Emma Scarlet
Jan 1 at 8:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992898%2fhow-to-communicate-between-websocets-using-javascript-as-client-and-python-as-we%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In my case I have done with this approach,
- I have created one JS file for WebSocket event handling methods(onOpen,onClose and onMessage) which is loaded on home page loading.
- In this file I have created one reference variable to hold events of WebSockets using (.prototype)
- Same like second step created two seperate methods for creating connection which is going to be called from home page and one connect method to connect the server
- In onMessage you can call your business method where you can put your logic
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
}
}
Thanks a lot helped a lot to get an idea. I'll try this out and accept
– Emma Scarlet
Jan 1 at 8:34
add a comment |
In my case I have done with this approach,
- I have created one JS file for WebSocket event handling methods(onOpen,onClose and onMessage) which is loaded on home page loading.
- In this file I have created one reference variable to hold events of WebSockets using (.prototype)
- Same like second step created two seperate methods for creating connection which is going to be called from home page and one connect method to connect the server
- In onMessage you can call your business method where you can put your logic
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
}
}
Thanks a lot helped a lot to get an idea. I'll try this out and accept
– Emma Scarlet
Jan 1 at 8:34
add a comment |
In my case I have done with this approach,
- I have created one JS file for WebSocket event handling methods(onOpen,onClose and onMessage) which is loaded on home page loading.
- In this file I have created one reference variable to hold events of WebSockets using (.prototype)
- Same like second step created two seperate methods for creating connection which is going to be called from home page and one connect method to connect the server
- In onMessage you can call your business method where you can put your logic
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
}
}
In my case I have done with this approach,
- I have created one JS file for WebSocket event handling methods(onOpen,onClose and onMessage) which is loaded on home page loading.
- In this file I have created one reference variable to hold events of WebSockets using (.prototype)
- Same like second step created two seperate methods for creating connection which is going to be called from home page and one connect method to connect the server
- In onMessage you can call your business method where you can put your logic
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
}
}
answered Jan 1 at 6:10
TheSagyaTheSagya
157
157
Thanks a lot helped a lot to get an idea. I'll try this out and accept
– Emma Scarlet
Jan 1 at 8:34
add a comment |
Thanks a lot helped a lot to get an idea. I'll try this out and accept
– Emma Scarlet
Jan 1 at 8:34
Thanks a lot helped a lot to get an idea. I'll try this out and accept
– Emma Scarlet
Jan 1 at 8:34
Thanks a lot helped a lot to get an idea. I'll try this out and accept
– Emma Scarlet
Jan 1 at 8:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992898%2fhow-to-communicate-between-websocets-using-javascript-as-client-and-python-as-we%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to Stack Overflow !!! ,,, though not websockets, I think you will find what you are looking for in this post; stackoverflow.com/questions/12232304/…
– SteveJ
Jan 1 at 4:22
Possible duplicate of How to implement server push in Flask framework?
– M.R.Safari
Jan 1 at 7:54