Locked [Socket] TCP Listener terminated

  • Thursday, May 10, 2012 9:27 AM
     
     

    Dear all,

    I am going to start the TCP Listener and will send the files to the specified listener port. I am using below code to start the listener. But find that when the file is send to the listener which will shutdown and caused the program to terminate. Do you know why and have any hints? Please let me know. Thanks for your help!!

    Int32 port = 1300;
          IPAddress localAddr = IPAddress.Parse("127.0.0.1");
         
          // TcpListener server = new TcpListener(port);
          TcpListener server = new TcpListener(localAddr, port);

          // Start listening for client requests.
          server.Start();

    • Moved by Alexander Sun Friday, May 11, 2012 8:19 AM Move to more appropriate forum (From:Visual C# General)
    •  

All Replies

  • Thursday, May 10, 2012 12:34 PM
     
     

    Hi,

    for accepting client requests you must call server.AcceptTcpClient() method. Take a look here So your code would be:

    Int32 port = 1300;
          IPAddress localAddr = IPAddress.Parse("127.0.0.1");
         
          // TcpListener server = new TcpListener(port);
          TcpListener server = new TcpListener(localAddr, port);

          // Start listening for client requests.
          server.Start();

    while(true)

    {

    TcpClient connectedClient = server.AcceptTcpClient();

    //Write your code to receive the file.

    }


    Bilhan silva


    • Edited by Centigradz Thursday, May 10, 2012 12:35 PM
    •