java - ttorrent 库 HttpResponseMessage 错误

标签 java android bittorrent

我正在尝试使用 ttorrent 库为 Android 创建 torrent 应用程序。 我遇到了一些问题。

05-29 23:07:23.388: E/AndroidRuntime(3681): FATAL EXCEPTION: bt-announce(..393337)

05-29 23:07:23.388: E/AndroidRuntime(3681): java.lang.NullPointerException

05-29 23:07:23.388: E/AndroidRuntime(3681): at com.turn.ttorrent.common.protocol.http.HTTPAnnounceResponseMessage.parse(HTTPAnnounceResponseMessage.java:105)

05-29 23:07:23.388: E/AndroidRuntime(3681): at com.turn.ttorrent.common.protocol.http.HTTPTrackerMessage.parse(HTTPTrackerMessage.java:51)

05-29 23:07:23.388: E/AndroidRuntime(3681): at com.turn.ttorrent.client.announce.HTTPTrackerClient.announce(HTTPTrackerClient.java:124)

05-29 23:07:23.388: E/AndroidRuntime(3681): at com.turn.ttorrent.client.announce.Announce.run(Announce.java:224)

05-29 23:07:23.388: E/AndroidRuntime(3681): at java.lang.Thread.run(Thread.java:856)

public static HTTPAnnounceResponseMessage parse(ByteBuffer data)
    throws IOException, MessageValidationException {
    BEValue decoded = BDecoder.bdecode(data);
    if (decoded == null) {
        throw new MessageValidationException(
            "Could not decode tracker message (not B-encoded?)!");
    }

    Map<String, BEValue> params = decoded.getMap();

    try {
        List<Peer> peers;

        try {
            // First attempt to decode a compact response, since we asked
            // for it.
            peers = toPeerList(params.get("peers").getBytes());
        } catch (InvalidBEncodingException ibee) {
            // Fall back to peer list, non-compact response, in case the
            // tracker did not support compact responses.
            peers = toPeerList(params.get("peers").getList());
        }

        return new HTTPAnnounceResponseMessage(data,
            params.get("interval").getInt(),
            params.get("complete").getInt(),
            params.get("incomplete").getInt(),
            peers);
    } catch (InvalidBEncodingException ibee) {
        throw new MessageValidationException("Invalid response " +
            "from tracker!", ibee);
    } catch (UnknownHostException uhe) {
        throw new MessageValidationException("Invalid peer " +
            "in tracker response!", uhe);
    }

参数中没有“interval”或“c​​omplete”或“inclomplete”等键。有两个键“peers”和“mininterval”。

据我了解,在我调用客户端方法下载后,它从跟踪器请求一些信息,然后尝试解析此信息。这就是错误所在。

那么,问题是为什么会这样呢?是库中有错误还是我出了什么问题?

最佳答案

问题到底是什么?

请编辑您的问题并添加更多详细信息。

最好包含 sscce .

在您的问题中添加一个指向出现此错误的 torrent 文件的链接。 你如何构建 ttorrent?

确认您看到的错误是在从 Android 运行时发生的,而在普通 Java 中不会发生。

您可以使用 git 从 github 获取 ttorrent 代码,或者单击 github 项目上的按钮下载 zip。

ttorrent 使用 Maven。如果您手动获取依赖项,您可能无法获得正确的版本。 您应该将代码作为 Maven 项目导入到 Eclipse 中。 Eclipse -> 文件 -> ...导入 -> Maven -> 现有 Maven 项目

在导航器 Pane 中。找到 ttorrent 项目并右键单击选择 Run As -> Maven Build ... 对于目标,输入“package”并单击“Run”。

我从 ttorrent 示例客户端开始,并添加了已知良好的路径 Ubuntu 13.04 torrent file还有一个要保存到的目录。

我在调试器中运行了代码,ttorrent 运行正常。它开始下载 Ubuntu,没有抛出异常或打印错误消息。

在您列出的行中,我看到参数映射有四个条目(“interval”、“complete”、“peers”、“incomplete”)。

这是我使用的客户端代码:

public class ClientTest
{

    public static void main(String[] args) throws NoSuchAlgorithmException
    {    
        try {
            SharedTorrent fromFile =
            SharedTorrent.fromFile(
            new File("j:/ubuntu-13.04-desktop-amd64.iso.torrent"),
            new File("j:/td"));
            Client client =
                new Client(InetAddress.getLocalHost(), fromFile);
            client.download();
            client.waitForCompletion();
        } catch (UnknownHostException ex) {
            Logger.getLogger(ClientTest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ClientTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

关于java - ttorrent 库 HttpResponseMessage 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16822484/

相关文章:

java - 使用 KSOAP2 序列化要发送的整数数组

java - 探戈计划 : Determine whether an IntersectionPointPlaneModelPair is aligned with Gravity

java - 如何将 Web 表单与 JAX-RS 结合使用

android - 在 libgdx 中,如何从后退按钮获取输入?

network-protocols - Bittorrent 协议(protocol)如何处理数据 block ?

p2p - 用于多人游戏的完全/半自主 P2P 网络的可行性如何?

java - 将 CrudRepository 接口(interface)扩展为基础接口(interface)

java - 如何在 webView 中向网站添加 CSS(填充)

Android转换月份数组

java - 通过 DataInputStream 连续读取套接字消息的正确方法是什么?