TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Philip Wrenn
NA
1
0
Problem with asynchronous NetworkStream - BeginRead / EndRead
Nov 27 2005 7:30 PM
I am reading data from a network stream between this application and an SMTP server. I am expecting a initial message from the SMTP serveer someting like "220 stmp.myserver.com ESMTP". The bytes received by the EndRead method seem to be about right for the expected message, although no data is being written into my readBuffer byte array.
Below is the relevant portion of my code and testing output.
// BEGIN CODE
private void BeginReadSmtp()
{
byte[] readBuffer = new byte[1024];
smtpStream.BeginRead(readBuffer, 0, readBuffer.Length, new AsyncCallback(EndReadSmtp),smtpStream);
}
void EndReadSmtp(IAsyncResult iar)
{
smtpStream = (NetworkStream)iar.AsyncState;
byte[] readBuffer = new byte[1024];
String data = "";
int bytesRead;
bytesRead = smtpStream.EndRead(iar);
data = String.Concat(data, Encoding.ASCII.GetString(readBuffer, 0, bytesRead));
while (smtpStream.DataAvailable)
{
smtpStream.BeginRead(readBuffer, 0, readBuffer.Length, new AsyncCallback(EndReadSmtp),smtpStream);
}
Console.WriteLine("BYTES RECEIVED:{0}",bytesRead);
Console.WriteLine("DATA:{0}",data);
}
// END CODE
PROGRAM OUTPUT IS AS FOLLOWS:
BYTES RECEIVED: 72
DATA:
Any suggestions?
Thanks.
Reply
Answers (
0
)
Dynamically generation in .Net
Retrieving return value of stored procedure(NOT OutPut Parameter)