473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Stream.BeginRead

hello,

i've a method in the form_load event witch calls 2 beginread
statements (one after the other :) )
problem: during the second call it seem's that the callback won't be
triggered.

i've tried to wait for several seconds before calling the second call
- no effect.

but (!) if i put the method into a timer event it work's pretty fine.
help!!!

i'm also open for code improvement, if you just say WTF to the
following code:

<code>
public void sendMessage(string Message, string LineTerminator)
{

//WAIT FOR FREE CONNECTION
while (Locked)
{
System.Threading.Thread.Sleep(10);

//USED FROM OUTSIDE FOR SYNCHRONISATION
//WAIT STATE
Pending = true;
}
Locked = true;

Pending = false;

msStream = getStream(eCLIENTS.PARAMETER);

MessageStream msMessage = new MessageStream();
msMessage.LineTerminator = LineTerminator + "\r\n";
msMessage.bMessage = new Byte[1];
msMessage.sMessage = new StringBuilder();

msStream.BeginRead(msMessage.bMessage, 0, 1, delCallBack, msMessage);
msStream.Write(Encoding.ASCII.GetBytes(Message + "\r\n"),
0,Message.Length + 2);
}

private void OnMessageReceived(IAsyncResult asyncResult)
{
MessageStream msMessage = (MessageStream) asyncResult.AsyncState;

msMessage.sMessage.Append(Encoding.UTF7.GetString( msMessage.bMessage));

if ( (msMessage.sMessage.Length >= msMessage.LineTerminator.Length)
&&

(msMessage.sMessage.ToString().EndsWith(msMessage. LineTerminator)))
{
//extern event
MessageReady(msMessage.sMessage.ToString());
Locked = false;
ClientConnection(eCLIENTS.PARAMETER,false);
}
else
{
msStream.BeginRead(msMessage.bMessage, 0, 1, delCallBack,
msMessage);
}
}

Aug 2 '07 #1
1 5291
ignore my question.
i've solved it via trivial synchron write and read commands - never
try to reinvent the wheel.

Aug 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: 0to60 | last post by:
I have a class that wraps a TcpClient object and manages all the async reading of the socket. It works really nice, and I use it all over the place. But there's this ONE INSTANCE where I create...
0
by: Galore | last post by:
Hello, I'm trying to make a simple socket application, something like a chat application, but when I run it, it shows the following error when the client connects to the server: "Unable to read...
1
by: Martin | last post by:
Hi Im trying to make a Client/Server where im going to encrypt the stream but i cant get it to work. I can recieve and send as long as im not trying to send/recieve encrypted. but when i am i cant...
0
by: Thomas Zöchling | last post by:
Hat jemand (schlechte) Erfahrungen mit Asynchronen NetworkStreams gemacht? In meiner Serveranwendung scheint die BeginRead Methode des NetworkStreams manchnmal den Stream nicht fertig zu lesen. ...
6
by: Stephen Brooker | last post by:
Hi all, I've got a basic TCP app that is giving me trouble. I have a separate class that takes care of the TCP connection, and uses the NetworkStreams BeginRead and EndRead with a callback...
3
by: Helge Jensen | last post by:
I am implementing a protocol which transmits messages. The messages are most naturally transferred using the a Stream so the protocol can communicate over serial-ports, network links, .... If...
0
by: Webster | last post by:
Hello, I have a program that asynchronously reads data from a host. However, whenever I call the BeginRead function, the async reading "loop" never seems to terminate. Why doesn't the EndRead...
0
by: Morgan Cheng | last post by:
I am using C# to write a crawler-like program. The program reads several URI pages sequentially and store HTTP response into a single byte array. The job should be done in specific time. So, I have...
0
by: vishnu | last post by:
Hi, Am trying to post the data over https and am getting error in httpwebresponse.getResponseStream.Please help me to get rid of this issue. Here is the message from immediate window ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.