title: Reading Streaming Data using python
body: <p>I have a server ip:port from where continuous data is coming. I want to read this data using python and want to transfer in some file. I got this sample code over internet and changed it according to my need.</p>
  
  <pre><code>import socket
  HOST = 'ip'   # use '' to expose to all networks
  PORT = 10001
  
  def incoming(host, port):
    """Open specified port and return file-like object"""
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # set SOL_SOCKET.SO_REUSEADDR=1 to reuse the socket if
    # needed later without waiting for timeout (after it is
    # closed, for example)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind((host, port))
    sock.listen(0)   # do not queue connections
    request, addr = sock.accept()
    return request.makefile('r', 0)
  # /-- network ---
  
  
  for line in incoming(HOST, PORT):
    print line,
  </code></pre>
  
  <p>After executing this, I am getting below error.</p>
  
  <pre><code>Traceback (most recent call last):
    File "read.py", line 24, in &lt;module&gt;
      for line in incoming(HOST, PORT):
    File "read.py", line 17, in incoming
      sock.bind((host, port))
    File "&lt;string&gt;", line 1, in bind
  socket.error: [Errno 99] Cannot assign requested address
  </code></pre>
  
  <p>Note: When I access ip:port using web browser, i could see data getting printed on it in text format.</p>
  
  <p>How should i proceed here?</p>