473,770 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stream.BeginRea d

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(str ing Message, string LineTerminator)
{

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

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

Pending = false;

msStream = getStream(eCLIE NTS.PARAMETER);

MessageStream msMessage = new MessageStream() ;
msMessage.LineT erminator = LineTerminator + "\r\n";
msMessage.bMess age = new Byte[1];
msMessage.sMess age = new StringBuilder() ;

msStream.BeginR ead(msMessage.b Message, 0, 1, delCallBack, msMessage);
msStream.Write( Encoding.ASCII. GetBytes(Messag e + "\r\n"),
0,Message.Lengt h + 2);
}

private void OnMessageReceiv ed(IAsyncResult asyncResult)
{
MessageStream msMessage = (MessageStream) asyncResult.Asy ncState;

msMessage.sMess age.Append(Enco ding.UTF7.GetSt ring(msMessage. bMessage));

if ( (msMessage.sMes sage.Length >= msMessage.LineT erminator.Lengt h)
&&

(msMessage.sMes sage.ToString() .EndsWith(msMes sage.LineTermin ator)))
{
//extern event
MessageReady(ms Message.sMessag e.ToString());
Locked = false;
ClientConnectio n(eCLIENTS.PARA METER,false);
}
else
{
msStream.BeginR ead(msMessage.b Message, 0, 1, delCallBack,
msMessage);
}
}

Aug 2 '07 #1
1 5333
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
7208
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 one of these things and it WON'T read data. If I set a breakpoint in my EndRead callback, it never goes off. NOTHING is different from anywhere else I use this class, its just this one place. Now, if I create a second constructor for my class...
0
3520
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 data from the transport connection.". I'm posting the code, so if somebody can help I'll be very grateful. private void DoListen() {
1
3453
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 send, recieve or both. The Send/Recieve Code is the same on both Server and client. Send/Recieve Code: private Stream Net() { if(Encrypted) {
0
3115
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. ... socket = socketForClient; buffer = new byte; networkStream = new NetworkStream(socketForClient); callbackRead = new AsyncCallback(this.OnReadComplete);
6
5764
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 function to deal with the server response. All works well and the data is received OK. Once all the data is received, the connection is closed and I fire an event indicating all is finished. The event is handled in the main form of the application and...
3
6464
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 the other party never answers I must timeout -- not block, and this gives me a problem, since the Stream concept in .NET does not reflect timeouts. If a timeout occurs I will still need to use the same Stream for more messages, for example re-sends....
0
1024
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 method return 0 when it is done reading?? This is the pseudo-code for my callback function: ReadData
0
1136
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 both size limit and time limit. My current solution is like this. use HttpWebResponse.GetResponseStream to get the I/O stream. Read from it with asynchronous BeginRead. In the callback, check whether time and space is up. If yes, then stop;...
0
2888
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 ?myResp.GetResponseStream() {System.Net.ConnectStream}
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.