Forum: Ruby Sending data types in a UDP packet

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1f344a0e2440aaba172145eae4f7c646?d=identicon&s=25 Isaac Wagner (ibw)
on 2009-05-03 20:19
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.
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2009-05-03 20:55
(Received via mailing list)
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
This topic is locked and can not be replied to.