title: Real time output whilst running Python
body: <p>I'm making a basic chatroom and I want the received messages to show up when I'm also typing a message. I've looked it up, but from what I can tell it only works with a GUI, and I would prefer not to write a GUI.</p>
  
  <pre><code>import socket
  import time
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  str_return = ("")
  str_send = ("blep")
  old = ("blep")
  port = input("Enter Port ")
  try:
      s.connect(("localhost", int(port)))
      print("Connecting")
      while True:
          str_send = input("Enter message: ")
          if str_send == ("exit"):
              break
          s.send(bytes(str_send, 'utf-8'))
          str_recv = s.recv(1024)
          print(str_recv.decode('utf-8'))
  s.close()
  except:
      print("setting up server")
      s.bind(('localhost', int(port)))
      s.listen(5)
      connect, addr = s.accept()
      connect.sendto(bytes(str_return, 'utf-8'), addr)
      print("Connection Address:" + str(addr))
      while True:
          str_send = input("Enter message: ")
          if str_send == ("exit"):
              break
          connect.sendto(bytes(str_send, 'utf-8'), addr)
          str_recv, temp = connect.recvfrom(1024)
          print(str_recv.decode('utf-8'))
  
  
  print("bye")
  </code></pre>
  
  <p>How can I make this work?</p>