title: connecting python to javascript for two-direction communication
body: <p>I would like to serve queries from a javascript code by python. But I am not experienced in this field at all. What I would like to build is something like this:</p>
  
  <blockquote>
    <p><strong>1. request.js</strong>:</p>
  </blockquote>
  
  <pre><code>open_connection('server.py');
  for (var i=0; i&lt;10; i++)
      document.write(request_next_number());
  close_connection('server.py')
  </code></pre>
  
  <blockquote>
    <p><strong>2. server.py</strong></p>
  </blockquote>
  
  <pre><code>x = 0
  while connected:
      if request:
          send(x)
          x = x + 1
  </code></pre>
  
  <p>I heard about JSON, but don't know if I should use it. (?) </p>
  
  <p>Could you please give me some code examples or guides how to implement the two files above?</p>