title: Unable to connect to ZooKeeper from C# application using apache .NET library
body: <p>I'm using Zookeeper v3.3.3+dfsg2-1ubuntu1, running on ubuntu vm. (The VM is running with a NAT network connection)</p>
  
  <p>On my development machine (windows 7), if I run: <code>zkCli.cmd -server 10.10.135.19:2181</code> it connects fine and I can perform <code>create</code>s, <code>get</code>s etc.</p>
  
  <p>I have a C# 4 application with a NuGet dependency on Org.Apache.ZooKeeper v1.0.0.0.</p>
  
  <p>I am using it in the following way:</p>
  
  <pre><code>  class watcher : IWatcher
    {
       private readonly ManualResetEventSlim _connected = new ManualResetEventSlim(false);
       private WatchedEvent _event;
  
       public void WaitUntilConnected()
       {
          _connected.Wait();
  
          if (_event == null) throw new ApplicationException("bad state");
          if (_event.State != KeeperState.SyncConnected)
             throw new ApplicationException("cannot connect");
       }
  
       public void Process(WatchedEvent @event)
       {
          _event = @event;
          _connected.Set();
       }
    }
  
    ...
  
    public void TestZooKeeper()
    {
       _countdownWatcher = new watcher();
       _zk = new ZooKeeper(
          Settings.Default.ZookeeperConnectionString, // 10.10.135.19:2181
          new TimeSpan(Settings.Default.ZookeeperConnectionTimeout), // 10000
          _countdownWatcher);
       _countdownWatcher.WaitUntilConnected();
    }
  </code></pre>
  
  <p>The problem is that this just hangs. On the zookeeper logs, I see the following:</p>
  
  <pre><code>2012-04-05 08:12:21,376 - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn$Factory@251] - Accepted socket         connection from /10.0.2.2:51057
  2012-04-05 08:12:21,379 - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@777] - Client attempting to establish new session at /10.0.2.2:51057
  2012-04-05 08:12:21,383 - INFO  [SyncThread:0:NIOServerCnxn@1580] - Established session 0x1367c91bf580047 with negotiated timeout 4000 for client /10.0.2.2:51057
  2012-04-05 08:12:22,500 - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn$Factory@251] - Accepted socket connection from /10.0.2.2:51059
  2012-04-05 08:12:22,502 - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@777] - Client attempting to establish new session at /10.0.2.2:51059
  2012-04-05 08:12:22,505 - INFO  [SyncThread:0:NIOServerCnxn@1580] - Established session 0x1367c91bf580048 with negotiated timeout 4000 for client /10.0.2.2:51059
  2012-04-05 08:12:26,000 - INFO  [SessionTracker:ZooKeeperServer@314] - Expiring session 0x1367c91bf580047, timeout of 4000ms exceeded
  2012-04-05 08:12:26,001 - INFO  [ProcessThread:-1:PrepRequestProcessor@387] - Processed session termination for sessionid: 0x1367c91bf580047
  2012-04-05 08:12:26,004 - INFO  [SyncThread:0:NIOServerCnxn@1435] - Closed socket connection for client /10.0.2.2:51057 which had sessionid 0x1367c91bf580047
  2012-04-05 08:12:28,001 - INFO  [SessionTracker:ZooKeeperServer@314] - Expiring session 0x1367c91bf580048, timeout of 4000ms exceeded
  2012-04-05 08:12:28,002 - INFO  [ProcessThread:-1:PrepRequestProcessor@387] - Processed session termination for sessionid: 0x1367c91bf580048
  2012-04-05 08:12:28,004 - INFO  [SyncThread:0:NIOServerCnxn@1435] - Closed socket connection for client /10.0.2.2:51059 which had sessionid 0x1367c91bf580048
  </code></pre>
  
  <p>And this continues until I kill the process manually, ie, the <code>WaitUntilConnected()</code> method never returns. (verified with debugging)</p>
  
  <p>It seems as if the client connection reaches the server fine, but the Watcher never realises this, nothing further happens on that channel and the server kills the connection, only for the client to retry. Any ideas what I'm doing wrong here?</p>