473,785 Members | 2,321 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 5334
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
3521
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
3454
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
3116
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
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10162
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
9959
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
8988
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
7509
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
6744
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
5396
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...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.