From: Brian Candler Date: 2010-07-16T01:32:45+09:00 Subject: Re: Sending packets over TCP server Zsdfhdfgasdf Gsfgsdgsdgsd wrote: > I'm making a TCP server in Ruby, and I still haven't figured out how I > can send packets the way it should be sent. I know how to receive > packets and such though... > > For example, one of the packets I need to send looks like this: > > Packet ID: 0x00 > Purpose: Server Identification: Response to a joining player. The user > type indicates whether a player is an operator (0x64) or not (0x00.) > Current protocol version is 0x07. > > Fields: > Packet ID Byte > Protocol Version Byte > Server name String > Server MOTD String > User Type Byte You need more detail than that. Is a string of a fixed size, or terminated by a null, or prefixed by a length byte, or something else? You can send raw data just by sticking the bytes a string, like this: client.write "\x00\x07foobar\x00baz\x07" For building such strings, Array#pack and String#unpack are going to be what you're looking for. >> [0,7,"foobar","baz",100].pack("CCZ*Z*C") => "\000\afoobar\000baz\000d" -- Posted via http://www.ruby-forum.com/.