@Override
    public void run() {
//        System.out.println("download meta data");// TODO
        try (Socket peerSocket = new Socket(peerIp, peerPort);
                OutputStream output = peerSocket.getOutputStream();
                InputStream input = peerSocket.getInputStream()) {
            byte[] handshakeMsg = new byte[68];
            handshakeMsg[0] = 19;
            System.arraycopy("BitTorrent protocol".getBytes(), 0, handshakeMsg, 1, 19);
            handshakeMsg[25] = 16;
            System.arraycopy(infoHash, 0, handshakeMsg, 28, 20);
            System.arraycopy(peerNodeId, 0, handshakeMsg, 48, 20);
            output.write(handshakeMsg);

            byte[] replyMsg = new byte[65535];
            int totalBytes = 0;
            int n;
            System.out.print("handshake reply:");
            byte[] lengthBytes = new byte[8];
            while ((n = input.read(lengthBytes, totalBytes + 4, 4 - totalBytes)) != -1) {
                totalBytes += n;
                if (totalBytes == 4) {
                    break;
                }
            }
            long length = ByteBuffer.wrap(lengthBytes).getLong();
            System.out.print("length prefix:" + length + ",");
            while ((n = input.read(replyMsg)) != -1) {
                totalBytes += n;
                if (n == 0) {
                    break;
                }
//                System.out.print(new String(replyMsg, 0, n));
            }
            System.out.println("total bytes:" + totalBytes);
        } catch (ConnectException ex) {
            Logger.getLogger(BtCrawler.class.getName()).log(Level.FINE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(BtCrawler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }