From: Brian Candler Date: 2010-12-17T00:13:28+09:00 Subject: Re: How to do UDP calls Luis G. wrote in post #968857: > As you might know, you can have this: > > http://9.rarbg.com:2710/announce > udp://tracker.openbittorrent.com:80/announce No, I haven't seen the udp:// URL format at all. Is there an RFC which describes it? > For the first one (HTTP) I just use this: ... > But for the second one (UDP) I can't use Mechanize, so I need to work > with the standard library as you told before. And not only that, you need to know what format data to put *inside* the UDP packet. That's what I was getting at. You need some documentation of the application-layer protocol, which sits inside the transport layer protocol. I guess it *might* be HTTP, complete with a full set of HTTP headers. Worth a try, if you have a valid URL to point at. You can use netcat (nc) to test: echo "GET /announce" | nc -u tracker.openbittorrent.com 80 and run sudo tcpdump -i eth0 -nn -s0 udp port 80 in another window to check for any replies. When I try that particular example, I get nothing back. > 1- The main idea is to create a socket, connect it to the remote host, > send the request and get the response, right? I guess so... > 2- do I need to include the 'udp://' in the host? Nope. The socket functions take hostnames/IP addresses, not URLs. There is a 'URI' class you can use to parse it out of the URL though. > 3- is ok to include the name of the field I want to send (?info_hash=) > in the data variable? That I have no idea, because I've not seen any documentation for this protocol. > 4- how can I get the response from the server? something like: > sock.recvfrom(1024)? Yes, recvfrom returns a tuple of [data, address_info]. Or I believe you could 'connect' the socket first, send, recv. > I tried several options and I had no success. > > Any clues? Look at a C implementation of this protocol, and port it to ruby? tcpdump -X an existing working client, and see what it sends/receives? Ask on a bittorrent development mailing list? -- Posted via http://www.ruby-forum.com/.