title: Are different telnet connections with the same endpoints valid in different threads?
body: <p>I'd like to connect to a telnet server multiple times and use each connection in its own thread. So, I'd be using multiple sessions that have the same endpoints concurrently.</p>
  
  <p>I'm using <code>TcpClient</code> and a very simple, home-made telnet library. In my tests, single connections work fine, and multiple connections in different threads work fine when I use a static lock object. When I remove the lock, I get unexpected responses from the server (it looks like the server is responding to a request made on a different thread).</p>
  
  <p>The thing that confuses me is that, when I run a single connection per application but multiple <em>applications</em> (which are running concurrently), everything works fine.</p>
  
  <p>Is what I am trying to do valid with telnet? Would there be a difference when using SSH?</p>
  
  <p><strong>This does not seem to work</strong>:</p>
  
  <pre><code>Application
      Client-
             \
              &lt;-&gt; Server
             /
      Client-
  </code></pre>
  
  <p><strong>This seems to work</strong>:</p>
  
  <pre><code>Application
      Client &lt;-&gt; Server
  Application
      Client &lt;-&gt; Server
  </code></pre>
  
  <p>I have verified that I am indeed creating different TCP connections (different instances of <code>TcpClient</code>) per session in the multi-threaded application.</p>