From: Brian Candler Date: 2010-12-17T05:58:47+09:00 Subject: Re: How to do UDP calls Luis G. wrote in post #968897: > connect input > 64-bit integer connection_id 0x41727101980 > 32-bit integer action 0 > 32-bit integer transaction_id 16 > > You told me that Array#pack will help me. This means that I need to put > the the content of the connect input in an array and pack it so I can > send it, right? > Actually I thought we need to have something like: > connection_id =>0x41727101980 > action => 0 > ... > > Anyway, see this example: > > data = Array.new > data << 0x41727101980 #connection_id > data << 0 #action > data << 16 #transaction_id > > host = 'tracker.openbittorrent.com' > port = 80 > > s = data.pack('q') #q?! There are three elements in the array 'data', so: s = data.pack('qNN') However 'q' may be wrong here, if you're on a little-endian machine. Unfortunately, Array#pack doesn't have a 64-bit network-order flag. I think you should use something like this: conn_id = 0x41727101780 s = [conn_id >> 32, conn_id & 0xffffffff, 0, 16].pack('NNNN') Then for debugging, to check you're sending what you think: STDERR.puts s.unpack("H*").first > BTW, I tried > > echo "GET /announce" | nc -u tracker.openbittorrent.com 80 > sudo tcpdump -i eth0 -nn -s0 udp port 80 > > and I got results: > 18:09:14.719638 IP 192.168.182.123.57232 > 95.215.62.26.80: UDP, length > 14 That's the outbound packet (from 192.168.182.123 local port 57232, to 95.215.62.26 port 80), and you got no response. -- Posted via http://www.ruby-forum.com/.