[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting binary data out of sockets



Russ,

>I assume the answer to this is pretty simple, but I don't see it. I'm
>opening a connection to a server I wrote (in C). The connection has to
>send a bunch of numeric data. I can put the data in an array and write it
>to the socket, but how do I read it as a binary on the client (Squeak)
>side?

One way to convert the bytes you read from a socket into a number is to put
the bytes into a ByteArray and then use ByteArray methods like:
#longAt:bigEndian: or #unsignedShortAt:bigEndian:, etc.  To extract
floating point values, you might have to write some new methods based on
these and on the methods in FloatArray.

If you plan on serving up numbers to multiple machines of different types,
it would be wise to convert the numbers to network byte order using
functions like htonl() before sending them.  Then the client only has to
worry about converting the numbers from network byte order to it's own byte
order. If you are transferring floating point numbers, you will also have
to worry about floating point representation issues.

Hope that gets you started....

Tom