user3592352
user3592352

Reputation: 1

Program stuck on AcceptTcpClient

I am using a modality emulator when i am connecting program with emulator, program hang on Accept Tcp Client..Why?

public virtual void Run()

{
  if (this.ss == null)

    return;

  TcpClient tcpClient = (TcpClient) null;

  while (!this.m_Stop)

  {

    try

    {

      tcpClient = this.ss.AcceptTcpClient();

      ThreadPool.QueueUserWorkItem(new WaitCallback(this.handler.Handle), (object) tcpClient);

    }

    catch (Exception ex)

    {

      MessageBox.Show(ex.ToString());

    }

   }

}

Here ss is the TcpListener

Upvotes: 0

Views: 1300

Answers (2)

steve cook
steve cook

Reputation: 3214

AcceptTcpClient() is a blocking method that you use when you are creating a TCP Server.

'Blocking' means that it will wait until a TCP client connects to it before returning.

Did you mean to create a TCP Client instead? If so, just use TCPClient.Connect(), passing the server IP and port that you are connecting to.

Upvotes: 2

Gigi
Gigi

Reputation: 29421

AcceptTcpClient() will block until a connection is received. The program will continue once a client connects to your TcpListener.

Upvotes: 1

Related Questions