Sending data types in a UDP packet

I

Isaac Wagner

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.
 
J

Joel VanderWerf

Isaac said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top