title: Basic Python client socket example
body: <p>I've been trying to wrap my head around how sockets work, and I've been trying to pick apart some sample code I found at <a href="http://www.pythonprasanna.com/Papers%20and%20Articles/Sockets/tcpclient_py.txt" rel="noreferrer">this page</a> for a very simple client socket program. Since this is basic sample code, I assumed it had no errors, but when I try to compile it, I get the following error message. </p>
  
  <blockquote>
    <p>File "client.py", line 4, in 
       client_socket.connect(('localhost', 5000))
     File "", line 1, in connect
     socket.error: [Errno 111] Connection refused</p>
  </blockquote>
  
  <p>I've googled pretty much every part of this error, and people who've had similar problems seem to have been helped by changing the port number, using 'connect' instead of 'bind,' and a few other things, but none of them applied to my situation. Any help is greatly appreciated, since I'm very new to network programming and fairly new to python.</p>
  
  <p>By the way, here is the code in case that link doesn't work for whatever reason.</p>
  
  <pre><code>#client example
  import socket
  client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  client_socket.connect(('localhost', 5000))
  while 1:
      data = client_socket.recv(512)
      if ( data == 'q' or data == 'Q'):
          client_socket.close()
          break;
      else:
          print "RECIEVED:" , data
          data = raw_input ( "SEND( TYPE q or Q to Quit):" )
          if (data &lt;&gt; 'Q' and data &lt;&gt; 'q'):
              client_socket.send(data)
          else:
              client_socket.send(data)
              client_socket.close()
              break;
  </code></pre>