TcpClient disposing
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: TcpClient disposing

Hybrid View

  1. #1
    Join Date
    May 2012
    Posts
    27

    TcpClient disposing

    Hi.
    I'm making a server/client project where a client can connect to my server and be able to chat and stuff.

    I seem to be having trouble with something that confuses me. If I connect my client to the server, then exit the client, and then try to re-connect, I get an error saying "cannot access a disposed object".

    This is my code right here

    Code:
    public static void ClientThread(TcpClient nClient)
            {
               
                while (nClient.Connected)
                {
                    
                    if (nClient.Client.Poll(20, SelectMode.SelectRead) == true && nClient.Available == 0) //To handle D/C
                    {
                        
                        break; //Exit loop
                    }
                    
                    if (nClient.Available > 0)
                    {
                    BufferHandler.HandleBuffer();
                }
    		}
    	}
    and this is where I seem to get my error

    Code:
    if (nClient.Client.Poll(20, SelectMode.SelectRead) == true && nClient.Available == 0) //To handle D/C
    Sockets and TcpClients really confuse me so if someone could help me out that would be awesome!
    thanks

  2. #2
    Join Date
    May 2012
    Posts
    27

    Re: TcpClient disposing

    Bump!

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center