title: Connect to Socket on localhost
body: <p>I have trouble connecting to my own <strong>socket</strong> on <strong>localhost</strong>.<br>
  <code>s.connect(('127.0.0.1', 4458))</code> (or "localhost") will just take forever,<br>
  and eventually <strong>timeout</strong> with <code>TimeoutError: [Errno 110] Connection timed out</code></p>
  
  <p>It should open port 4458, another script will then send some chars to it. Both scripts are supposed to run on the same Raspberry Pi, while 'server' one will execute with sudo (to access the GPIOs) and one without, being a chat bot.</p>
  
  <p>I have no trouble running the server on the Pi (with <strong>python 3.4.1</strong>) and the client on my Laptop (mac, python 3.4.2). </p>
  
  <p>Also it does work in reverse direction, server script on the laptop and client on the Raspberry.</p>
  
  <p>As final test, it works with both, the server and the client on the said macbook.</p>
  
  <p>Just server + client on the Pi does not work.</p>
  
  <p>The program freezes </p>
  
  <p>My shortened code if it helps:</p>
  
  <pre><code># $ sudo python3 server.py
  
  __author__ = 'luckydonald'
  import socket # server
  import time # wait for retry
  import threading
  class Server(threading.Thread):
      port = 4458;
      QUIT = False
  
       def run(self):
          s = socket.socket()
          failed = True
          print ("Starting Server on Port %d" % (self.port))
          while failed:
              try:
                  s.bind(("", self.port))
              except Exception as err:
                  print(err)
                  print("Port assignment Failed. Retring in 1 second.")
                  time.sleep(1)
              else:
                  failed = False
                  print("Success.")
          while not self.QUIT:
              print("Listening!")
              conn, addr = s.accept() # freezes here
              print("Got something: %s , %s" %(str(conn), str(addr)))
              while not self.QUIT:
                  result = conn.recv(1)
                  print("Got result: " + str(result))
  server = Server();
  server.daemon = True
  server.run();
  # server.start();
  </code></pre>
  
  <p>And for the client:</p>
  
  <pre><code># python3 cilent.py
  s = socket.socket()
  print("connecting...")
  s.connect(("localhost",4458)) # also tried "172.0.0.1" # freezes here
  print("connected!")
  s.sendall("+".encode("utf-8"))
  s.sendall("-".encode("utf-8"))
  s.close()
  </code></pre>
  
  <p>It will result in this:</p>
  
  <p><img src="https://i.stack.imgur.com/yLGLm.png" alt="Picture of console output"></p>