[bittorrent] compact ip problem

André ghost.ued at gmail.com
Wed Aug 22 22:08:21 EDT 2007


"You want to save each section of the
IP address as a unsigned 8 bit integer. "

actually, in a 32 bit integer xD

Dazen, the operator you need is not >>. It's >>> .

 Look for java bitwise operators, and you will see the difference.


i did not understand your code, but the size seems right: each pair Ip
and port uses 6 bytes.

here is my code:

byte[] ipembytes =InetAddress.getByName(ip);

                       peerByteResponse[ actualLength] = ipembytes[0];
                       peerByteResponse[ actualLength+1] = ipembytes[1] ;
                       peerByteResponse[ actualLength+2] = ipembytes[2] ;
                       peerByteResponse[ actualLength+3] = ipembytes[3] ;
                       peerByteResponse[actualLength+4]= (byte)(port >>>8);
                       peerByteResponse[actualLength+5]= (byte)port;

(peerByteResponse is a bytre array with the peers string)



More information about the BitTorrent mailing list