title: Why would connection refused when client and server is running on the same process?
body: <p>I'm having a problem running a client and server in the same process. Every time I try to connect my client to the server, it would give me this error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "dirWatch.py", line 78, in &lt;module&gt;
  startDirWatch(sLink)
  File "dirWatch.py", line 68, in startDirWatch
  sC.client('/home/homer/Downloads/test.txt')
  File "/home/homer/Desktop/CSC400/gsync/serverClient.py", line 15, in client
  sock.connect((host,port))
  File "&lt;string&gt;", line 1, in connect
  socket.error: [Errno 111] Connection refused
  </code></pre>
  
  <p>Here's the code I used, I'm basically trying to make a file-synchronization program. I'm new to StackOverflow so please excuse me if I haven't provided more details. Here is the code I'm testing the client and server code:</p>
  
  <pre><code>thread.start_new_thread(sC.server ,('localhost', 50001))
  sC.client('/home/homer/Downloads/test.txt')
  </code></pre>
  
  <p>Here is the actual code for client server, it's pretty basic, I just want them to connect:</p>
  
  <pre><code>def client(filename, host = defaultHost, port = defaultPort):
      sock = socket(AF_INET, SOCK_STREAM)
      sock.connect((host,port))
      sock.send((filename + '\n').encode())
  
      sock.close()
  
  def serverthread(clientsock):
      sockfile = clientsock.makefile('r')
      filename = sockfile.readline()[:-1]
      try:
          print filename
  
      except:
         print('Error recieving or writing: ', filename)
      clientsock.close()
  
  def server(host, port):
      serversock = socket(AF_INET, SOCK_STREAM)
      serversock.bind((host,port))
      serversock.listen(5)
      while True:
          clientsock, clientaddr = serversock.accept()
          print('Connection made');
          thread.start_new_thread(serverthread, (clientsock,))
  </code></pre>
  
  <p>Any help or advice would be appreciated. Thanks for reading.</p>