1

I am new to web development and have a JavaScript code I downloaded, I want it to call some python functions to do calculations. As I research I find a lot of information and I am not sure yet what to do. I will present to knowledge I have gathered and then ask my questions:

1) In the following issue: connecting python to javascript for two-direction communication , there is an explanation about how to open a python socket using SocketServer, and how to open a JS socket using socketIO... but I didn't understand from this how the connection is established.

2) The best example I have found is that one: https://flask-socketio.readthedocs.io/en/latest/, it seems to explain how to establish a connection using the flask library and the socketIO library. My problem with this guide is that I'm not sure how to implement it on localHost.

My questions:

1) Can you help me (maybe by referencing to some guide) create a simple program that will establish a two-way connection between a JS and a python programs? for example, when the user clicks on a button it sends a number to the python program, it adds 1 to it, sends it back to the JS program and prints the result to the browser log?

2) I am not sure how to make it work with an actual site. I tries to run the program from the first source and open localHost, but I got an error. how do I make my JS code run with localHost?

3) the JS code I downloaded run on a specific website. I need it to communicate with the program I am writing (it's a machine learning program that should learn to play a game). Does that fact changes the methods needed to solve the first two questions?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.