binary array, packing and unpacking?
Ragnar Hojland Espinosa
ragnar at linalco.com
Fri Feb 14 10:48:29 UTC 2003
I'm making a little tcp/ip server using SocketStream.st and I'm having
trouble finding a way to pack/unpack data from binary to strings and to
shorts and longs, and to do ntohl and similar.
So basically I have what you can see below, and I haven't figured out how to
| data |
^ version, name, description. "???"
Supposing version is a integer which should be converted to its int32
represetation, name is a string, and description is a string, how would you
convert the stuff to a single array?
| stream magic version |
stream _ SocketStream on: socket
stream binary; autoFlushOff.
magic _ stream next: 4.
port _ stream next: 2.
stream nextPutAll: servers size.
servers do: [ :each | stream nextPutAll: each asBytes ].
How would you convert port to an integer? And how to ntohs it? And magic
to a string?
Newbiely yours ;)
Ragnar Hojland - Project Manager
Linalco "Especialistas Linux y en Software Libre"
http://www.linalco.com Tel: +34-91-5970074 Fax: +34-91-5970083
More information about the Squeak-dev