title: TCP-IP Communication via Python and an open port of a SSH connection
body: <p>This is a newbie question for TCP-based communication in Python. I am trying to establish a TCP-based communication between two *NIX systems via an SSH tunnel and the Python socket module. I have used the two first examples "echo server" and "echo client" from this Python MOTW website: <a href="http://www.doughellmann.com/PyMOTW/socket/tcp.html" rel="nofollow">http://www.doughellmann.com/PyMOTW/socket/tcp.html</a>.</p>
  
  <p>The communication worked fine on the same *NIX system (HOST1) but failed over the ssh tunnel.</p>
  
  <p>I logged into the second *NIX system with <code>ssh -L 10000:HOST2:10000 USERNAME@HOST2</code>. Then I played around and tried to establish the communication in the same manner by starting the python script for the server on HOST2 and the script for the client on HOST1. This I got on stderr:</p>
  
  <pre><code>python test_socket_client.py 
  connecting to localhost port 10000
  Traceback (most recent call last):
  File "test_socket_client.py", line 10, in &lt;module&gt;
  sock.connect(server_address)
  File "&lt;string&gt;", line 1, in connect
  socket.error: [Errno 111] Connection refused
  </code></pre>
  
  <p>When I started server and client vice versa on HOST1 and HOST2, respectively, I got the same message.</p>
  
  <p>What am I doing wrong?</p>