title: C# program hangs on Socket.Accept()
body: <p>I created a server "middleman" application that uses sockets and multi-threading techniques (ServerListener is run in a new thread). I found early on that when I would use the Socket.Accept() method, the program would hang indefinitely, waiting for that connection to happen.  The problem is, as far as I can tell there is no reason for it not to.  </p>
  
  <p>I spent a good portion of the day trying lots of different things to make it work, and somewhere something changed because it suddenly started working for a while.  However, as soon as I accidentally chose a different data source than "localhost" for the client application, the problem popped back up again.  I have tried running the program without the firewall OR antivirus running, but no luck.  The client program IS set to connect on port 10000.  Here is my code:</p>
  
  <pre><code>    public void ServerListener() {
          UpdateStatus("Establishing link to server");
          server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
          server.Bind(new IPEndPoint(IPAddress.Any, defaultPort));
          server.Listen(queue);
          UpdateStatus("Accepting Connections");
          while (true) {
              Socket client = default(Socket);
              try {
                  client = server.Accept();
                  if (client != null) {
                      ++count;
                      UpdateCount(count.ToString());
                      new Thread(
                      () =&gt; {
                          Client myclient = new Client(client, defaultPort, this);
                      }
                      ).Start();
                  }
              }
              catch( Exception ex ){
                  MessageBox.Show(ex.ToString());
                  client.Close();
              }
          }
      }
  </code></pre>
  
  <p>It will run just fine right up until server.Accept(), then hangs.  As stated, it did work for a while earlier, but is now hanging again.  I've tried to see if any other programs are using port 10000, and they aren't.  I went over and over this with a friend, and we couldn't find the problem.  Please help!</p>
  
  <p><em>EDIT</em> To be clear, I do know that Accept is a blocking call.  The client program makes the connection on port 10000, but this program keeps on waiting on the Accept as if nothing happened.  It did work for a time, so I know the connection is working like it is supposed to from the client program's end.  However, I can't fathom why this program is now acting like that connection never happens, and continues to wait on the Accept.</p>