🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #564

Re: Using TIdTCPServer

#564
From: Peter
Date: Thu, 24 Jan 2008 17:40
60 lines
3715 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Peter" <piotrtrzeciak@yahoo.com> wrote in message 
>news:4798a5e1$1@newsgroups.borland.com...
>
>> The original code was very simple:
><snip>
>
>Your original code was reading endlessly, as TIdTCPStream::Read() always 
>returns the same Count value that you pass in, so imageData->msg would 
>always be greater than 0 until an exception occured.  Such logic is easy to 
>reproduce using the code I already gave you earlier:
>
>    while( imageData->msg > 0 )
>    {
>        // assuming rcv_buffer is a TIdBytes.  ReadBytes() will not exit 
>until all 32000
>        // bytes have been received.  The same was true for 
>TIdTCPStream::Read() as well...
>        AContext->Connection->IOHandler->ReadBytes(imageData->rcv_buffer, 
>32000);
>        imageData->msg = 32000;
>        fwrite(&imageData->rcv_buffer[0], imageData->msg, 1, 
>imageData->imgFile);
>    }
>
>> but now, I'm trying this:
><snip>
>> and I get no data from the socket.
>
>Then your client is not sending any data at all, or is more likely sending 
>data after a small delay.  You are exiting your loop if the InputBuffer has 
>no data each time you check it.  The first time you check the InputBuffer, 
>if no data has arrived yet, you exit the loop right away.  At the very 
>least, you should increase your timeout value to give the data a better 
>chance of catching up to how fast your reading code is running.
>
>With that said, the best option is to forget looping at all.  Have the 
>client send the data size before sending the actual data.  Then your server 
>knows exactly how many bytes to expect, and can call ReadBytes() or 
>ReadStream() just once to do all of the work.  In fact, that is what you 
>said in your original posting that you were doing, but you are not doing 
>that anymore in this latest code snippet.  So by introducing InputBuffer 
>checking into your code, which you did not need in the first place, you have 
>made the code operate worse, not better.
>
>
>Gambit 
>
>

Thanks for your answers!!!
I wish this was that simple :-)
Unfortunately, the "client" in this case is a Mainframe imaging system (from Big Blue, which does not make it easier).
The whole communication sequence was "reverse-engineered" from the network traces a few years ago. Now... we get two kinds of data on the socket: image (binary, where we have no control how it's sent by the Mainframe), and data (which we control, and the communication is done exactly how your suggested :-)).
When getting the binary data, first I get a piece that contains a binary code that says "image", and then I have to read that image (not knowing how big it is).
Thanks for your help!!! If you have any points for me, I greatly appreciate them!!!

Peter
Technical Details
Message-ID: <4798db8f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <478e1c34$1@newsgroups.borland.com> <478e4760@newsgroups.borland.com> <4798a5e1$1@newsgroups.borland.com> <4798cf30$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,452e664b18b0b56c
X-Google-Attributes: gid11508e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Peter" <piotrtrzeciak@yahoo.com>
Sender: "Peter" <piotrtrzeciak@yahoo.com>
Reply-To: "Peter" <piotrtrzeciak@yahoo.com>
Subject: Re: Using TIdTCPServer
Newsgroups: borland.public.cppbuilder.internet.socket
X-User-Info: 207.45.45.41     
References: <478e1c34$1@newsgroups.borland.com> <478e4760@newsgroups.borland.com> <4798a5e1$1@newsgroups.borland.com> <4798cf30$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <4798db8f$1@newsgroups.borland.com>
Date: 24 Jan 2008 10:40:15 -0700
X-Trace: newsgroups.borland.com 1201200015 207.105.83.66 (24 Jan 2008 10:40:15 -0700)
Lines: 61
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail