Board index » delphi » Sending and receving a record structure using SendBuf and ReceiveBuf

Sending and receving a record structure using SendBuf and ReceiveBuf

Hi,

Can anyone breifly explain the best way to send and receive data held in a
record using sockets. It seems that there is not much help available on the
web for this topic (in english anyway!). I've noticed several different ways
by using a buffer of char or even using pointers. The main problem is that I
have strings in my record structure..... I've figured out that I need to
convert these to arrays of char, but if I set these arrays to be large
(10000) say, I never get the full transmission on the server.

Any help or explainations would be greatly appreciated.

Cheers

Wayne

 

Re:Sending and receving a record structure using SendBuf and ReceiveBuf


The way I handle it: send a record as a kind of header with some basic
information about the type of message being sent and the size of the
remaining data, then send the string seperately. The other end first
receives the header and can use the size specified in the header to get the
string back correctly without having to define a fixed-size string...

Quote
"Wayne Jones" <jugs_of_ju...@tomgreen.com> wrote in message

news:3cbcb92f$1_1@dnews...
Hi,

Can anyone breifly explain the best way to send and receive data held in a
record using sockets. It seems that there is not much help available on the
web for this topic (in english anyway!). I've noticed several different ways
by using a buffer of char or even using pointers. The main problem is that I
have strings in my record structure..... I've figured out that I need to
convert these to arrays of char, but if I set these arrays to be large
(10000) say, I never get the full transmission on the server.

Any help or explainations would be greatly appreciated.

Cheers

Wayne

Re:Sending and receving a record structure using SendBuf and ReceiveBuf


Few approaches:

1) Determine the size of the message and use the SendStreamWithSize methods.
On the receiving end, you can wait for the size and ReceiveFromStream or
simply call something like ReceiveStreamWithSize (sorry, these are DxSock
calls, but INDY and others have similar methods).

2) Encode the structure using a versatile encoding format (like ASN.1/DER or
XML).  Then write a receiver that knows how to look for the lengh indicator
and receive the message.

3) Write a custom transport protocol that combines #1 and #2 (i.e. send a
custom header that includes the size and other attributes.  You would have a
receiver that looks for the header, and when found, reads the rest of the
message.

While I prefer the second option for its versatility (i.e. you can encrypt
messages and encode authentication information as well a pull information
out by path), the first option will invariably be faster while the second
will give you the ability to access specific fields in your message in an
easy manner.

I actually the third technique as I have a high peformance transport layer
that sends DER encoded messages for processing.  I use newly announced
StrSecII's ASN.1 routines to do my dirty work. http://www.streamsec.se
But, you could just as easily use XML (or similar) instead.

Cheers,

Charles

Quote
"Wayne Jones" <jugs_of_ju...@tomgreen.com> wrote in message

news:3cbcb92f$1_1@dnews...
Quote
> Hi,

> Can anyone breifly explain the best way to send and receive data held in a
> record using sockets. It seems that there is not much help available on
the
> web for this topic (in english anyway!). I've noticed several different
ways
> by using a buffer of char or even using pointers. The main problem is that
I
> have strings in my record structure..... I've figured out that I need to
> convert these to arrays of char, but if I set these arrays to be large
> (10000) say, I never get the full transmission on the server.

> Any help or explainations would be greatly appreciated.

> Cheers

> Wayne

Re:Sending and receving a record structure using SendBuf and ReceiveBuf


Thanks for both your replies :-)

Quote
"Wayne Jones" <jugs_of_ju...@tomgreen.com> wrote in message

news:3cbcb92f$1_1@dnews...
Quote
> Hi,

> Can anyone breifly explain the best way to send and receive data held in a
> record using sockets. It seems that there is not much help available on
the
> web for this topic (in english anyway!). I've noticed several different
ways
> by using a buffer of char or even using pointers. The main problem is that
I
> have strings in my record structure..... I've figured out that I need to
> convert these to arrays of char, but if I set these arrays to be large
> (10000) say, I never get the full transmission on the server.

> Any help or explainations would be greatly appreciated.

> Cheers

> Wayne

Re:Sending and receving a record structure using SendBuf and ReceiveBuf


Quote
"Charles Stack" <char...@codycomp.com> wrote in message <news:3cbd8713_1@dnews>...
> Few approaches:

> 1) Determine the size of the message and use the SendStreamWithSize methods.
> On the receiving end, you can wait for the size and ReceiveFromStream or
> simply call something like ReceiveStreamWithSize (sorry, these are DxSock
> calls, but INDY and others have similar methods).

> 2) Encode the structure using a versatile encoding format (like ASN.1/DER or
> XML).  Then write a receiver that knows how to look for the lengh indicator
> and receive the message.

> 3) Write a custom transport protocol that combines #1 and #2 (i.e. send a
> custom header that includes the size and other attributes.  You would have a
> receiver that looks for the header, and when found, reads the rest of the
> message.

> While I prefer the second option for its versatility (i.e. you can encrypt
> messages and encode authentication information as well a pull information
> out by path), the first option will invariably be faster while the second
> will give you the ability to access specific fields in your message in an
> easy manner.

> I actually the third technique as I have a high peformance transport layer
> that sends DER encoded messages for processing.  I use newly announced
> StrSecII's ASN.1 routines to do my dirty work. http://www.streamsec.se
> But, you could just as easily use XML (or similar) instead.

With a schema that is an ASN.1 module, you can either encode in a binary
format such as DER or the compact PER (Packed Encoding Rules), or you can
even generate an XML document by using XER (XML Encoding Rules).

More information on ASN.1: http://asn1.elibel.tm.fr
More information on ASN.1/XML: http://asn1.elibel.tm.fr/xml

O. Dubuisson

Other Threads