Results 1 to 2 of 2

Thread: TCPListener will not accept incoming connection

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    247

    TCPListener will not accept incoming connection

    I am having an issue recieving data from my asyncronous server on my non-asyncronous client (for reasons of variable interaction). Can someone tell me why I can't recieve a packet back from my server with the following code:

    Code:
     public static void StartListening()
            {
                TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 7345);
                listener.Start(1);
    
                while (true)
                {
                    Socket socket = listener.AcceptSocket();
                    NetworkStream stream = new NetworkStream(socket);
    
                    byte[] readData = new byte[1024];
                    int readBytes = 0;
                    readBytes = stream.Read(readData, 0, 1024);
    
                    string Message = Encoding.ASCII.GetString(readData).Substring(0, readBytes);
                    HandleMessage(Message);
                    stream.Close();
                    break;
                }
                listener.Stop();
            }
    It is really starting to bother me and I need some help, thanks!



  2. #2
    Lively Member
    Join Date
    May 2008
    Location
    Manila, Philippines
    Posts
    81

    Re: TCPListener will not accept incoming connection

    i think you should create a thread that will start receiving packets after you a client has connected to your server...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width