title: Socket in Python3, listening port
body: <p>I want to listen port in Python3.</p>
  
  <pre><code>import socket
  
  sock = socket.socket()
  sock.bind(('', 9090))
  sock.listen(1)
  conn, addr = sock.accept()
  
  print 'connected:', addr
  
  while True:
      data = conn.recv(1024)
      if not data:
          break
      conn.send(data.upper())
  
  conn.close()
  </code></pre>
  
  <p>The data which I want to listen, looks like:</p>
  
  <pre><code>8,0,0,test,0,2016/07/19,14:40:57.938,2016/07/19,14:40:57.938,,,,,,,,,,,,0
  8,0,0,test,0,2016/07/19,14:40:57.965,2016/07/19,14:40:57.965,,,,,,,,,,,,0
  3,0,0,test,0,2016/07/19,14:41:04.687,2016/07/19,14:41:04.687,,2475,,,,,,,,,,0
  ..
  </code></pre>
  
  <p>that is I need read until <code>'\n'</code>
  So I need to change this block, but I dont know how..</p>
  
  <pre><code>data = conn.recv(1024)
  if not data:
      break
  conn.send(data.upper())
  </code></pre>
  
  <p>I want replace nc:</p>
  
  <pre><code>nc -k -l -p 30003 | python3 script.py
  </code></pre>
  
  <p>where script.py</p>
  
  <pre><code>while True:
      for string in sys.stdin:
  </code></pre>
  
  <p>Also I need reconnect if something wrong, server must be ready take all data any time, just like <code>nc -k -l -p 30003 | python3 script.py</code></p>