In article <
MPG.291cd0ca3...@newszilla.xs4all.nl>,
use...@mandersDELETE.DELETEorg says...
> In article <
MPG.291b7e6ad...@news.east.earthlink.net>,
>
Asga...@mindspring.com says...
> > Anyway, since I have your ear, what's the deal with the TCP SEND
> > function? It looks as if sending string data is cool, but what about
> > binary data? Or, do I not understand what the function actually does?
> > If I have something like this :
> > TYPE cal_data
> > offset AS DWORD
> > data AS DWORD
> > cal AS DWORD
> > END TYPE
> >
> > and I want to send a packet of those 12 bytes to a client or server, how
> > would TCP SEND know the length of the data, can it send the data? The
> > more I get into this the less I like the built in functions, or am I
> > missing something here too?
>
> TCP SEND just sends all the bytes in the string you send. You can use a
> user defined type as argument for TCP SEND and it will send SIZEOF
> (cal_data) bytes.
I will have to try that.
I just used the socket command
send (alias as ssend) (socket, buffer, size, flags)
and went from there. Every time I tried something with the built in
command, it seemed to stop at the first 0 byte. Like it was trying to
use a NULL terminated string as the data type, but that could have been
the way I was calling the function too.
>
> You can use TCP SEND to send binary data, but it's wise to put your data
> in a packet, for instance starting with a LONG for "# bytes to follow",
> a "type of data" indicator, the data itself, followed by a checksum,
> followed by an LONG "end of packet" indicator.
That's fine *IF* you have control over what both ends of the pipe do.
Some of the time I have to go along with the spec of the device we are
talking to, and that may be any method. The nice thing is most of the
items I have to deal with are ours, or the TCP stack is a stripped down
version that doesn't handle fragmented packets, so you can be guaranteed
that all data will fit inside a single frame and there will be plenty of
time for each packet to reach the server before the next one is created.
>
> At the receiving end you first read 4 bytes to determine the length of
> the packet, then you know how many more bytes to read. If communication
> happens to get out of sync, you can read bytes until the last 4 are the
> "end of packet" indicator.
In the utility I am working on now, that shouldn't be a problem. Each
packet is built and flushed by the client so there is only one data
structure per packet, and that keeps it more like a UDP system with the
"guaranteed" delivery of TCP.
Anyway, thanks for your time, I will give the TCP SEND function another
try, but for now calling Winsock directly has gotten me out of the woods
for now. The rest is just fleshing out all the error checking and HMI
goodies.