By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,208 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,208 IT Pros & Developers. It's quick & easy.

Socket communication to POP3 problem

P: n/a
Hi,
I developed an application to read email from POP3 server. Some of the
codes are below:
-------------------------------------------------------------------------------
Server = new TcpClient(_MailServer, 110);
......
private string sendCommand(string command) {
byte[] szData;

NetStrm = Server.GetStream();
RdStrm = new StreamReader(Server.GetStream());
RdStrm.DiscardBufferedData();

// add CRLF to the command
command += "\r\n";

szData = System.Text.Encoding.ASCII.GetBytes(command.ToChar Array());
NetStrm.Write(szData, 0, szData.Length);
//NetStrm.Flush();

string s = "";

while(RdStrm.Peek() > -1) {
s += RdStrm.ReadLine() + "\r\n";
}
return s;
}
-------------------------------------------------------------------------------
This is the core function to read data from socket.

In POP3 command there is one "RETR 1" to read all content of email. It
should return something like:
-------------------------------------------------------------------------------
+OK 2134 octets
Date: Mon, 24 Jan 2005 11:38:19 -0500
Message-Id: <20***********************@company.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
From: "Hardy Wang" <ha********@company.com>
Reply-To: <ha********@company.com>
To: <te**@company.com>
X-Mailer: <IMail v8.15>
X-RCPT-TO: <te**@company.com>
Status: U
X-UIDL: 406403936

Body of email....
-------------------------------------------------------------------------------
It works fine on my local machine (machine1), on one of the server
(server1), I can get all the content properly. But after I moved program to
another server (server2), RdStrm.Peak() will return -1 after retrieving
first line of content, which is "+OK 2134 octets" (drive me mad!). My next
POP3 command is "DELE 1" to remove this mail, at this step socket stream
returned the remaining part of mail content! So it looks there is a delay.
On my local machine (against same POP server as server2), RdStrm.Peak()
won't return -1 until I have all content in stream returned (good).
machine1 <--> POP3
server2 <--> POP3

My question is in which situation, socket will return stream differently
against same target? Both machines have .Net 1.1 and service pack 1
installed.

Thanks for any suggestion!
--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.