[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Coding a server

Vernier --

1/5/2009 7:24:00 AM

Hey,

I'm porting some old c++ code for a server to ruby, and I can't figure
out what's the correct way of doing the network packet parsing

I'm using eventmachine for the networking code but when a packet is
received it must be parsed and depending on the header the packet will
have one format or another, and each of these would have an associated
reply format, I'm not quite sure on how to code this while keeping it
clean

Any ideas on how you would do this?
also, in cpp I'm using structs for the packet formats, but I have no
idea on how to do that in ruby
--
Posted via http://www.ruby-....

6 Answers

Last Chance Power Drive

1/3/2009 3:22:00 AM

0

On Jan 2, 7:11 pm, HalS007 <HalS...@aol.com> wrote:
> On Jan 2, 7:08 pm, spoonful2 <spoonf...@gmail.com> wrote:
>
> > On Jan 2, 9:27 pm, I Worship Satan <millha...@intergate.com> wrote:
>
> > > That's what I heard.
>
> > I didn't even know about this arena until 2 weeks ago. I kinda doubt
> > he'll play there unless it's there and in LA but I don't know. The
> > Inland Empire....there's nothing Empire about it.
>
> Why are you even responding to this nonesense?

Me and Spoonful go way back.

FACT - I said back in 2007 he would be touring in 2009. This info was
laughed off.

FACT - I said he would be playing in Milwaukee in late Aug 2008
several months before the official announcement. This info was just
ignored.

I think you are just jealous because I can actually deliver
information that has some substance breaking your monopoly, which is
really just in your silly deluded head. I on the other hand have a
PROVEN track record when it comes to breaking news on RMAS. So laugh
and deflect all you want. When the 2009 tours comes through town, we
will know who was posting accurate information.

And YES this will be in addition to another appearance in L.A. proper,
probably the Hollywood Bowl, which last I heard is still very
interested in hosting a show.

Jeremy Hinegardner

1/5/2009 8:27:00 AM

0

On Mon, Jan 05, 2009 at 04:24:02PM +0900, Vernier -- wrote:
> Hey,
>
> I'm porting some old c++ code for a server to ruby, and I can't figure
> out what's the correct way of doing the network packet parsing
>
> I'm using eventmachine for the networking code but when a packet is
> received it must be parsed and depending on the header the packet will
> have one format or another, and each of these would have an associated
> reply format, I'm not quite sure on how to code this while keeping it
> clean
>
> Any ideas on how you would do this?
> also, in cpp I'm using structs for the packet formats, but I have no
> idea on how to do that in ruby

Take a look at packetfu http://code.google.com/p...

enjoy,

-jeremy

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org


Vernier --

1/5/2009 8:52:00 AM

0

Jeremy Hinegardner wrote:
> On Mon, Jan 05, 2009 at 04:24:02PM +0900, Vernier -- wrote:
>>
>> Any ideas on how you would do this?
>> also, in cpp I'm using structs for the packet formats, but I have no
>> idea on how to do that in ruby
>
> Take a look at packetfu http://code.google.com/p...
>
> enjoy,
>
> -jeremy

the bindata dependency for packetfu is exactly what I was looking for
for the structs, thanks a lot
--
Posted via http://www.ruby-....

Joel VanderWerf

1/5/2009 5:42:00 PM

0

Vernier -- wrote:
> Jeremy Hinegardner wrote:
>> On Mon, Jan 05, 2009 at 04:24:02PM +0900, Vernier -- wrote:
>>> Any ideas on how you would do this?
>>> also, in cpp I'm using structs for the packet formats, but I have no
>>> idea on how to do that in ruby
>> Take a look at packetfu http://code.google.com/p...
>>
>> enjoy,
>>
>> -jeremy
>
> the bindata dependency for packetfu is exactly what I was looking for
> for the structs, thanks a lot

Another option:

http://redshift.sourceforge.net/b...

I don't know bindata, but from a quick glance at the docs I see that it
does handle related fields, like length fields that specify the length
of another field. BitStruct does *not* do that.

Another difference is that BitStruct is a subclass of string, so it is
very efficient to send a bitstruct to a socket or file or perform other
string operations.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Vernier --

1/5/2009 8:47:00 PM

0

Joel VanderWerf wrote:
> Another option:
>
> http://redshift.sourceforge.net/b...
>
> I don't know bindata, but from a quick glance at the docs I see that it
> does handle related fields, like length fields that specify the length
> of another field. BitStruct does *not* do that.
>
> Another difference is that BitStruct is a subclass of string, so it is
> very efficient to send a bitstruct to a socket or file or perform other
> string operations.

amazing performance, for creating 10k instances of the same simple
struct (ruby 1.9 rc1):

user system total real
bindata 3.681000 0.000000 3.681000 ( 3.827000)
bit-struct 0.063000 0.000000 0.063000 ( 0.057000)

so bit-struct is actually a good choice for networking without any
modifications
--
Posted via http://www.ruby-....

Joel VanderWerf

1/5/2009 9:19:00 PM

0

Vernier -- wrote:
> Joel VanderWerf wrote:
>> Another option:
>>
>> http://redshift.sourceforge.net/b...
>>
>> I don't know bindata, but from a quick glance at the docs I see that it
>> does handle related fields, like length fields that specify the length
>> of another field. BitStruct does *not* do that.
>>
>> Another difference is that BitStruct is a subclass of string, so it is
>> very efficient to send a bitstruct to a socket or file or perform other
>> string operations.
>
> amazing performance, for creating 10k instances of the same simple
> struct (ruby 1.9 rc1):
>
> user system total real
> bindata 3.681000 0.000000 3.681000 ( 3.827000)
> bit-struct 0.063000 0.000000 0.063000 ( 0.057000)
>
> so bit-struct is actually a good choice for networking without any
> modifications

Exactly. If you have big packets, and only need to access a few fields
(esp. fixed length), bit-struct is especially efficient. But if you want
to use accessors a lot, then other libs might be better. With
bit-struct, each field access may require pack/unpack, bit
masking/shifting, etc.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407