-1

I have a JavaScript code running on internet browser and in the same machine in local host is running a python code.

I need to find a way to communicate between them.

Socket client-server is not possible because JavaScript don´t support sockets.

How to Use Sockets in JavaScript\HTML?: "There is no facility to use general-purpose sockets in JS or HTML. It would be a security disaster, for one."

And communication through server not interest me. I need a direct communication on localhost.

Is there any way to communicate with JavaScript and localhost without sockets?

Community
  • 1
  • 1
user3782779
  • 1,669
  • 3
  • 22
  • 36

2 Answers2

1

No, by the definition JavaScript cannot use TCP/IP sockets because that would be super super big security hole in the web security model.

You can use

  • HTTP requests (AJAX)

  • WebSockets

  • WebRTC

... to communicate with localhost. The easiest solution is to spin up a SimpleHTTPServer and then make JavaScript AJAX requests against it.

Please note that these communications might not work with HTML files opened file:// and you might need to use a local dev server.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
0

httprelay.io requires no additional libraries and can be used for simple http client to client communication. In your case on browser side use AJAX calls and on Python side use any HTTP client.

Jonas
  • 4,683
  • 4
  • 45
  • 81