In the specific protocol I'm writing a script for, I need to send a lot
of different data types through the packet, such as U32, and S8.
(Unsigned 32 bit, signed 8 bit). Does ruby support these types of
variables? How can I send them through a packet?
I'm still learning about networking and ruby, so if I said anything that
doesn't make sense, please forgive me.
···
--
Posted via http://www.ruby-forum.com/.
Isaac Wagner wrote:
In the specific protocol I'm writing a script for, I need to send a lot
of different data types through the packet, such as U32, and S8.
(Unsigned 32 bit, signed 8 bit). Does ruby support these types of
variables? How can I send them through a packet?
I'm still learning about networking and ruby, so if I said anything that
doesn't make sense, please forgive me.
The basic way of constructing packets in ruby is with Array#pack, and String#unpack on the other end. See the ri docs or the pickaxe book, or ask back here for more help.
There are some libraries that give you a little language for describing and manipulating packets, which can simplify your code and make it easier to maintain. I wrote bit-struct[1] and there are at least two others[2][3].
[1] http://raa.ruby-lang.org/project/bit-struct
[2] http://rubyforge.org/projects/bindata
[3] http://metafuzz.rubyforge.org/binstruct
···
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407