-1

你们能告诉我为什么我无法接收数据吗?
我使用了来自http://www.bittorrent.org/beps/bep_0015.html的 UDP Tracker 协议

这是我尝试从 udp://tracker.openbittorrent.com:80/announce 获取信息时的代码

        Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        client.Connect("tracker.openbittorrent.com", 80);

        byte[] conPacket = new byte[16];
        byte[] temp = BitConverter.GetBytes(0x41727101980);
        byte[] temp2 = BitConverter.GetBytes(0);
        byte[] temp3 = BitConverter.GetBytes(new Random().Next(0, 65535));
        Array.Copy(temp, 0, conPacket, 0, 8);
        Array.Copy(temp2, 0, conPacket, 8, 4);
        Array.Copy(temp3, 0, conPacket, 12, 4);
        client.Send(conPacket);

        byte[] recvPacket = new byte[16];
        client.Receive(recvPacket); <--------------- Waiting for response
        client.Close();
4

1 回答 1

1

好的,经过几个小时的研究,我最终决定使用 Wireshark 来查找请求数据包。

我发现我的包裹顺序不对。;(

这是新代码。

        Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        client.Connect(tracker, port);

        byte[] conPacket = new byte[16];
        byte[] temp = BitConverter.GetBytes(0x41727101980).Reverse().ToArray();
        byte[] temp2 = BitConverter.GetBytes(0);
        byte[] temp3 = BitConverter.GetBytes(new Random().Next(0, 65535));
        Array.Copy(temp, 0, conPacket, 0, 8);
        Array.Copy(temp2, 0, conPacket, 8, 4);
        Array.Copy(temp3, 0, conPacket, 12, 4);
        //Connect to the protocol
        client.Send(conPacket);

        byte[] response = new byte[16];
        client.Receive(response);

它现在正在工作!

于 2013-04-09T00:12:47.900 回答