Greg Chambers wrote:
>   def send_data( data_str )
>     data_struct = DataStruct.new
>     size_struct = SizeStruct.new
>     data_struct.message = data_str
>     size_struct.message_length = DataStruct.round_byte_length

       size_struct.message_length = data_struct.length

>     @tcp_sock.write( size_struct.to_s )
>     @tcp_sock.write( data_struct.to_s )
>   end

That was the main problem. You were getting the minimum length of any 
instance of DataStruct, which is 0, instead of the length of the packet 
you had assembled.

A minor point: you generally don't need all those to_s calls, since 
BitStruct < String. I would replace

     return data_struct.to_s

with

     return data_struct.message

even though it's the same in this case (just in case you add a field 
before message).

Otherwise, this is pretty much the right approach to managing discrete 
messages using a length field. Your code works for me with a few edits.

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