Eric, <div>by using the thread, it essentially becomes your timer event.</div><div><br></div><div>To Oversimplify how I use blocking sockets on a client/server where the server wants to send me information at any time..</div>
<div><br></div><div>Create a Thread</div><div>Thread has a sendmessage buffer queue,</div><div>Thread has a receivemessage buffer queue. </div><div><br></div><div>(This scenario is more useful when sending packets of data with predetermined size... not so great for streaming info)</div>
<div><br></div><div>The thread code essentially tests and maintains the server connection and does the following type thing.. use TEvent or some signal to communicate with the main app.. Indy maintains small databuffers, but you really want to be taking the data off the TCP stack into your own buffers as fast as you can, otherwise the server cant keep sending when the buffer is full.</div>
<div><br></div><div>while not terminated do</div><div>begin</div><div> if TCP.connected then</div><div> begin</div><div> with Connection.IOHandler do</div><div> begin</div><div><br></div><div> CheckForDataOnSource(0);// ReadFromStack(false,1,false);<br>
</div><div> CheckForDisconnect(True);</div><div><br></div><div> if not InputBufferISEmpty then<br></div><div> // grab the data and put it in the receive queue</div><div><br></div><div><br></div><div> if sendqueue not empty then sendthedata.. </div>
<div><br></div><div><br></div><div><br></div><div> sleep </div><div><br></div><div> end;</div><div><br></div><div>end;<br><br><div class="gmail_quote">On Thu, Dec 4, 2008 at 9:31 AM, Eric A <span dir="ltr"><<a href="mailto:eaa603@hotmail.com">eaa603@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>
Kyley,<br>
<br>
No program design yet. Questions:<br>
<br>
1) Inside the thread - do I have to implement a timer event to periodically check the buffer (since there's no "data received" event)? <br>
<br>
2) What properties do I read to determine if there's received data available? <br>
<br>
3) Do I need to use another Indy component in conjunction with the TCPClient for the buffering etc?<br>
<br>
<br>
Paul,<br>
<br>
I'll take a look at that site. Are you using ICS extensively?<br>
<br>
<br>
Thanks,<br>
Eric<br>
<br>
<br>
<br>
<br><br> <br>
<hr>
<br>
Date: Thu, 4 Dec 2008 09:21:03 +1300<br>From: <a href="mailto:kyleyharris@gmail.com" target="_blank">kyleyharris@gmail.com</a><br>To: <a href="mailto:delphi@delphi.org.nz" target="_blank">delphi@delphi.org.nz</a><br>Subject: Re: [DUG] Indy Sockets - How to Receive Asynchronously<div>
<div></div><div class="Wj3C7c"><br><br>Indy is blocking, so typically on the client side, you would create a waiting thread that you sit the TCPClient inside and loop a readtimeout until the resultbuffer has some data. At that point produce a local event so that your main thread can grab the TCPClient and read the information.<br>
<div><br></div>
<div>without knowing your actual program design and how your TCP layer interacts with your main application its hard to offer any detailed advise, sorry. <br><br>
<div>On Thu, Dec 4, 2008 at 9:14 AM, Paul <span dir="ltr"><<a href="mailto:paul.blommaerts@telenet.be" target="_blank">paul.blommaerts@telenet.be</a>></span> wrote:<br>
<blockquote style="padding-left:1ex;border-left:#ccc 1px solid">
<div>
<div><font face="Arial">Indy works blocking only</font></div>
<div><font face="Arial">Use ICS instead, they work blocking or non blocking.</font></div>
<div><font face="Arial">check <a href="http://www.overbyte.be/" target="_blank">www.overbyte.be</a></font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Paul</font></div>
<blockquote style="padding-right:0px;padding-left:5px;margin-left:5px;border-left:#000000 2px solid;margin-right:0px">
<div>
<div></div>
<div>
<div style="font:10pt arial">----- Original Message ----- </div>
<div style="background:#e4e4e4;font:10pt arial"><b>From:</b> <a title="eaa603@hotmail.com" href="mailto:eaa603@hotmail.com" target="_blank">Eric A</a> </div>
<div style="font:10pt arial"><b>To:</b> <a title="delphi@delphi.org.nz" href="mailto:delphi@delphi.org.nz" target="_blank">Delphi UsersGroup</a> </div>
<div style="font:10pt arial"><b>Sent:</b> Wednesday, December 03, 2008 8:55 PM</div>
<div style="font:10pt arial"><b>Subject:</b> [DUG] Indy Sockets - How to Receive Asynchronously</div>
<div><br></div>I have a situation where I need to communicate with a communications server using Indy TCP sockets. <br> <br>After sending the command the server returns an "OK" response with a second or two to acknowledge the acceptance of the command, however the reponse from the end device (returned via the server) may take several minutes to eventuate (or a else the sever returns a timeout message). I need to be able to buffer the responses, be aware of when new strings arrinve, and carry on with other tasks. This threading aspect shouldn't be an issue as I understand that Indy is naturally multitrheaded by design.<br>
<br>I'm not familiar with using the Indy sockets and since there's no "received data event" (due to the nature of the design) I'm wondering how I capture the asynchronous responses sensibly?<br> <br>
Does anyone have some code to show me how to use the Indy 10 TCPClient component in this way (for the receive part) ? Its probably pretty simple but I need to get my head around it quickly.<br> <br>Thanks<br> <br>Eric<br>
<br>
<hr>
Start searching now <a href="http://a.ninemsn.com.au/b.aspx?URL=http://www.allrealestate.co.nz/cgi-bin/rsearch?a%3Dbhp%26t%3Dren%26cu?rsf%3Dmsnz_textlink&_t=26000&_r=REANZ_tagline&_m=EXT" target="_blank">Rental properties galore.</a> </div>
</div>
<br>
<hr>
<br>_______________________________________________<br>NZ Borland Developers Group - Delphi mailing list<br>Post: <a href="mailto:delphi@delphi.org.nz" target="_blank">delphi@delphi.org.nz</a><br>Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz" target="_blank">delphi-request@delphi.org.nz</a> with Subject: unsubscribe
<br></blockquote></div><br>_______________________________________________<br>NZ Borland Developers Group - Delphi mailing list<br>Post: <a href="mailto:delphi@delphi.org.nz" target="_blank">delphi@delphi.org.nz</a><br>Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz" target="_blank">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<br></blockquote></div><br><br clear="all"><br>-- <br>Kyley Harris<br>Harris Software<br>
+64-21-671-821<br></div><br></div></div><div class="WgoR0d"><hr>MSN NZ Travel <a href="http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Ftravel%2Emsn%2Eco%2Enz&_t=771497011&_r=MSN_NZ_travel_hmtagline&_m=EXT" target="_blank">Get inspired - dream, research, plan and book your next holiday online with </a></div>
</div>
<br>_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<br></blockquote></div><br><br clear="all"><br>-- <br>Kyley Harris<br>Harris Software<br>
+64-21-671-821<br>
</div>