Board index » delphi » Data Received how to?

Data Received how to?

Hi,

I want to use the IDTCPCLIENT to communicate with a server. I'm placing a request and I'm waiting the
server to send some data back. I do not know the size of the data from the begging and I can't control if
the server will add the data size in front of the message how can I make sure that there are no more
packets to be received, all data has arived safelly and the size of the data in order to retreive them into a
buffer ?

Thank you for any help.

Regards
Johnnie.

 

Re:Data Received how to?


Quote
Johnnie <N...@Noware.non> wrote in message news:3b94b0a0_1@dnews...
> Hi,

> I want to use the IDTCPCLIENT to communicate with a server. I'm placing a

request and I'm waiting the
Quote
> server to send some data back. I do not know the size of the data from the

begging and I can't control if
Quote
> the server will add the data size in front of the message how can I make

sure that there are no more
Quote
> packets to be received, all data has arived safelly and the size of the

data in order to retreive them into a

Quote
> buffer ?

Given what you have stated above, you can not.  TCP sockets transfer byte
streams.  Your server must conform some protocol above TCP to allow the
communication of anything other than a stream.  It is to this protocol that
you must look to identify 'data size' 'last packet' etc.  Raw TCP/IP alone
will not do.

Rgds,
Martin

Re:Data Received how to?


Hi Martin,

Thank you for your quick replay.

From what you say i assume the the DataAvailable property of the  the netmaster powersocket
component is just an indicator that there are data to be readen from the component's internal buffer. Is
this possible with the IDTCPClient?

Thanks once more.

regards
Johnnie.

Re:Data Received how to?


Try to make your data separte form your start and end of data
something like

procedure TServerForm.IdTCPServer1Connect(AThread: TIdPeerThread);
begin
  AThread.Connection.WriteLn('start recieve data');
end;

procedure TServerForm.IdTCPServer1Execute(AThread: TIdPeerThread);
var Scommand : String
begin
  while not ........ do begin
//   Write your filestream here

  end;
  AThread.Connection.WriteLn('Done sending');
end;

this way your can detect whem sending starts en when your done sending data
just check op textvalue "Done" and then  AThread.Connection.Disconnect;

place it all in a Try except just be be sure

Fons Seesink
Actisoft

"Johnnie" <N...@Noware.non> schreef in bericht news:3b94cab7_2@dnews...

Quote
> Hi Martin,

> Thank you for your quick replay.

> From what you say i assume the the DataAvailable property of the  the

netmaster powersocket
Quote
> component is just an indicator that there are data to be readen from the

component's internal buffer. Is
Quote
> this possible with the IDTCPClient?

> Thanks once more.

> regards
> Johnnie.

Re:Data Received how to?


Hi,

As I have allready said I do not have any control over the server side so what I really need is a way to start
reading when data has arrived to the Clients buffer and then start reading until there are no data left.

Thank you for your responce.

Regards
Johnnie.

Re:Data Received how to?


Basically, without an  underlying protocol, you can't be certain no more
data will arrive unless the server disconnects the socket connection (then
no more data can be expected).  As somebody else pointed out, TCP will give
you a bi-directional stream of data.  What you do with it is your business.

My suggestion to you is to rethink your problem and possibly redesign both
client and server protocols.   I suspect that the information you need is
present in the server's specifications.  Typically, there will be some sort
of header, the data, and a trailer.  You may need to examine the data as it
arrives and see if you can find these parts.  This will require some sort of
state machine or stream parser.  Good luck.

You also might want to smack the designers of your server upside their head
as well for producing something that is so poorly designed in the first
place.

Charles

Quote
"Johnnie" <N...@Noware.non> wrote in message news:3b94b0a0_1@dnews...
> Hi,

> I want to use the IDTCPCLIENT to communicate with a server. I'm placing a

request and I'm waiting the
Quote
> server to send some data back. I do not know the size of the data from the

begging and I can't control if
Quote
> the server will add the data size in front of the message how can I make

sure that there are no more
Quote
> packets to be received, all data has arived safelly and the size of the

data in order to retreive them into a
Quote
> buffer ?

> Thank you for any help.

> Regards
> Johnnie.

Re:Data Received how to?


Quote
Johnnie <N...@Noware.non> wrote in message news:3b94ffaa_1@dnews...
> Hi,

> As I have allready said I do not have any control over the server side so

what I really need is a way to start
Quote
> reading when data has arrived to the Clients buffer and then start reading

until there are no data left.

Quote

> Thank you for your responce.

The problem is defining 'there are no data left'.  TCP does not know 'there
are no data left' and so your TCP client cannot supply you with an event for
this, apart from, maybee, a disconnection.  Even this is not general &
absolute.  Some FTP servers, for example, will resume a file download after
a disconnection & reconnection.  FTP can do this because it is written into
the FTP protocol, which uses TCP as transport.

The fact that there is a  'there are no data left' event is part of your
protocol definition.    You expect this at the client and, therefore, it
must be sent at the server.  If your server cannot indicate, in the data
stream, 'when there are no data left' then your server is useless for your
purpose and it's developers really do need a 'slap upside the head' or some
serious downsizing :)

Rgds,
Martin

Re:Data Received how to?


Quote
>The problem is defining 'there are no data left'.  TCP does not know
>'there are no data left' and so your TCP client cannot supply you with
>an event for this, apart from, maybee, a disconnection.  Even this is
>not general & absolute.  Some FTP servers, for example, will resume a
>file download after a disconnection & reconnection.  FTP can do this
>because it is written into the FTP protocol, which uses TCP as
>transport.

Well you know it  and now I know it as well but the people that are incharge
of this don't so I'll try to take this one step at the time, let me give them the
first step to start which is a way to know if there is any data in to the buffer
to start reading. When they will encounter the second problem I have
allready created a demo to help them do it the right way.

Regards
Johnnie.

Re:Data Received how to?


That's the ticket.  Show them the correct way and give them a working
solution so they CAN'T say no.

Charles

Quote
"Johnnie" <N...@Noware.non> wrote in message news:3b95e9bc$1_2@dnews...
> >The problem is defining 'there are no data left'.  TCP does not know
> >'there are no data left' and so your TCP client cannot supply you with
> >an event for this, apart from, maybee, a disconnection.  Even this is
> >not general & absolute.  Some FTP servers, for example, will resume a
> >file download after a disconnection & reconnection.  FTP can do this
> >because it is written into the FTP protocol, which uses TCP as
> >transport.

> Well you know it  and now I know it as well but the people that are
incharge
> of this don't so I'll try to take this one step at the time, let me give
them the
> first step to start which is a way to know if there is any data in to the
buffer
> to start reading. When they will encounter the second problem I have
> allready created a demo to help them do it the right way.

> Regards
> Johnnie.

Other Threads