1 Replies - 16756 Views - Last Post: 07 April 2008 - 05:21 AM Rate Topic: -----

#1 cygnusX   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 159
  • Joined: 19-May 07

Disconnect/Reconnect TcpClient

Posted 06 April 2008 - 11:25 PM

I have connection with POP3 server
TcpClient client;

SslStream stream;

void Connect()
{

  client = new TcpClient();
  client.Connect("pop.gmail.com", 995);
  stream = new SslStream(client.GetStream());
  stream.AuthenticateAsClient("pop.gmail.com");
}

ReadMessages()
{
  Connect()
  //getting the message
  int length = stream.Read(readBuffer, 0, readBuffer.Length);
  message = Encoding.ASCII.GetString(readBuffer, 0, length);

  //Handle the incoming messages from the server
}


Then at some some moment i close the stream and the TcpClient and after some time i call the ReadMessages() method again.But this exception occured when i connect to the server and try to read the incoming data - "The Read method cannot be called when another read operation is pending.".What's wrong?I have closed the stream and client before initialize the new instances,what's that pending read operation?

This post has been edited by cygnusX: 06 April 2008 - 11:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Disconnect/Reconnect TcpClient

#2 zakary   User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: Disconnect/Reconnect TcpClient

Posted 07 April 2008 - 05:21 AM

you have a stream.Read method called but you never close that stream, so when you try and read it again your application knows it sent it and thinks you didn't read it. So, you need to close that stream once the message has been read by calling stream.Close();

This post has been edited by zakary: 07 April 2008 - 05:23 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1