Board index » delphi » Sending Data Throught TCP Connection using Indy Components

Sending Data Throught TCP Connection using Indy Components

How can I send a variable like this one...

SharedFile: record
                    array[0..99] of string;
                    Who: string;
                  end;

... throught a TCP connection, using Indy Components, directly... (without
send one string at a time, in this case)?

Thanks...

 

Re:Sending Data Throught TCP Connection using Indy Components


Quote
Mario Macedo <[email protected]> wrote in message news:[email protected]
> How can I send a variable like this one...

> SharedFile: record
>                     array[0..99] of string;
>                     Who: string;
>                   end;

> ... throught a TCP connection, using Indy Components, directly... (without
> send one string at a time, in this case)?

Though I have only just started changing over to Indy, I doubt that  you can achieve
what you want to do with any component set.  The elements of your record are not
contiguous in memory  because of the dynamically-allocated nature of long strings.
If you can put up with short strings, eg. string[255], and use the 'packed' directive,
you could send such a record in one op.  Due to the nature of TCP, however, you
must allow for your data arriving in chunks.

A 'special' string structure for packeting may well be best, maybee contiguous null-
terminated strings with a 'header' structure containing the total length of the structure,
or something like that, so as not to waste space in the record with filler/dontCare bytes
that just  eat up net bandwidth.

Rgds,
Martin

PS.  Don't forget the 'packed', at both ends.  Without it, really wierd things will happen,
usually after delivery to customers.

Re:Sending Data Throught TCP Connection using Indy Components


i'm sorry, but let's see if i understood...

you want me to change this:

SharedFile: record
                    array[0..99] of string;
                    Who: string;
                  end;

to this:

SharedFile: packed record
                    names: array[0..99] of string[255];
                    Who: string;
                  end;

if this is it, how to i send this?

Quote
"Martin James" <[email protected]> wrote in message

news:[email protected]
Quote

> Mario Macedo <[email protected]> wrote in message

news:[email protected]
Quote
> > How can I send a variable like this one...

> > SharedFile: record
> >                     array[0..99] of string;
> >                     Who: string;
> >                   end;

> > ... throught a TCP connection, using Indy Components, directly...
(without
> > send one string at a time, in this case)?

> Though I have only just started changing over to Indy, I doubt that  you
can achieve
> what you want to do with any component set.  The elements of your record
are not
> contiguous in memory  because of the dynamically-allocated nature of long
strings.
> If you can put up with short strings, eg. string[255], and use the
'packed' directive,
> you could send such a record in one op.  Due to the nature of TCP,
however, you
> must allow for your data arriving in chunks.

> A 'special' string structure for packeting may well be best, maybee
contiguous null-
> terminated strings with a 'header' structure containing the total length
of the structure,
> or something like that, so as not to waste space in the record with

filler/dontCare bytes

- Show quoted text -

Quote
> that just  eat up net bandwidth.

> Rgds,
> Martin

> PS.  Don't forget the 'packed', at both ends.  Without it, really wierd
things will happen,
> usually after delivery to customers.

Re:Sending Data Throught TCP Connection using Indy Components


Quote
Carlos Silva <[email protected]> wrote in message news:[email protected]
> i'm sorry, but let's see if i understood...

> you want me to change this:

> SharedFile: record
>                     array[0..99] of string;
>                     Who: string;
>                   end;

> to this:

> SharedFile: packed record
>                     names: array[0..99] of string[255];
>                     Who: string;
>                   end;

Well, this is certainly better.   May not be ideal, but will work.  As for sending it,
once you have a connection then I presume, (not 100% Indy-savvy yet!),  that
one of the Indy TCP objects has a 'write' method that you can call, maybee:

var mySharedFile:SharedFile;
blah..
blah..
IndySocketThingy.write(@mySharedFile,sizeOf(mySharedFile));

You may, or may not, need the '@', just depends on how the write is declared.  In the
end, it all comes down to a winSock call with an address & length.  Maybee someone
else with more experience knows the correct Indy syntax.

The not-ideal thing about this form of record declaration is that it is big.  It is 25K even
if the strings are nearly empty.  That is why I suggest that maybee you cold define your
own string type especially for network comms, or/and, maybee have a netWrite
method/proc that converts the easy-to-use 'long string' structure above-top to the more
compact structure you have defined & sends it.

Rgds,
Martin

Other Threads