Home > Software engineering >  For bt download, and achieved many peer's IP address and port port, but every time all can not
For bt download, and achieved many peer's IP address and port port, but every time all can not

Time:05-16

For even the top peer, I tried to shut down the machine all firewalls, tried dozens of different peer for returning from the tracker server, most of these peer ping make sense, but it is not even, either return error: remote computer actively refused, or the remote computer for a long time no response,

Here is my simplified code:

 

Public value struct peerInfo
{
Int32 piAddress;
Int16 psPort;
};

System: : Void fmNewDLTask: : connect_PeersList_Test ()
{

IPEndPoint ^ iPeerEndPoint;

Array ^ peer_handshake_bytes=gcnew array (0 x44) {0};//peer handshake messages is a fixed length of 68 bytes of the message

Array ^ arrbsBitProtocol=Encoding: : UTF8 - & gt; GetBytes (" BitTorrent protocol ");

Array X6b ^ info_SHA1={0, 0 x51, x11, 0 0 x39, 0 x7b, 0 x26, xec 0, 0 x26,
Xa1 0 xa, 0 x35, 0, 0 x58, 0 xd3, 0 xa2, 0 xf9, 0 x95, x64, 0 0 xae, 0 x78, 0 xb5};

Array ^ peer_id_SHA1={x5a x2d 0, 0 x41, 0, 0 x32, 0 x30, 0 x36, 0 x30, 0 x2d, 0 xe6, x64, 0 0 x36, 0 xc4,
Xd9 x9c 0, 0 x2c, 0, 0 x35, 0 XFC, 0 xd2, 0 xea, 0 x34};

Array X4bb7 x718c4c6a ^ pInfo={{0, 0}, {0 x3dad4080, 0 x3a98},
X3a98 x6f2b7aad {0, 0}, {0 x7804a824, 0 x3a98},
Xab520253 {0, 0 x0}, {0 xafa27d72, 0 x3a98}, {0 xdb93ad47, 0 x3a98}};

Peer_handshake_bytes [0]=0 x13;//=decimal 19
Peer_handshake_bytes - & gt; Copy (peer_handshake_bytes arrbsBitProtocol, 0, 1, arrbsBitProtocol - & gt; Length);
//8 byte to retain the default value is 0 (draft to retain bytes is defined)
Peer_handshake_bytes - & gt; Copy (peer_handshake_bytes info_SHA1, 0, 0 x1c, info_SHA1 - & gt; Length);
Peer_handshake_bytes - & gt; Copy (peer_handshake_bytes peer_id_SHA1, 0, 0 x30, peer_id_SHA1 - & gt; Length);

System: : Net: : Sockets: the Socket ^ peer_Socket=nullptr;

for (int i=0; I & lt; PInfo - & gt; Length; I++)
{
//the Debug: : WriteLine (" 0 X + pInfo "[I] piAddress. ToString (" X") + "(" + (IPEndPoint (pInfo [I] piAddress, pInfo [I] psPort). The ToString ()) +") \ t0x "+ pInfo [I] psPort. ToString (" X") + "(" + pInfo [I] psPort. The ToString () +") ");
The Debug: : WriteLine (" 0 X + pInfo "[I] piAddress. ToString (" X") + "\ t0x + pInfo" [I] psPort. ToString (" X ") + "(" + pInfo [I] psPort. The ToString () +") ");

IPeerEndPoint=gcnew IPEndPoint (htonl (pInfo [I] piAddress), htons (pInfo [I] psPort));
//iPeerEndPoint=gcnew IPEndPoint (htonl (pInfo [I] piAddress), 80);

Peer_Socket=gcnew Socket (AddressFamily: : InterNetwork, SocketType: : Stream, ProtocolType: : Tcp);
Bool blockingState=peer_Socket - & gt; Blocking;

Try
{
Peer_Socket - & gt; The Connect (iPeerEndPoint);//always this line error: either the remote computer actively refused, or the remote computer for a long time no response,

if (! Peer_Socket - & gt; Connected)
{
The Debug: : WriteLine (DateTime: : Now the ToString () + "connection Peer" + iPeerEndPoint - & gt; Address - & gt; The ToString () +
":" + iPeerEndPoint - & gt; The Port + "Connect failed!" );

}

Peer_Socket - & gt; Blocking=false;

If ((peer_Socket - & gt; Send (peer_handshake_bytes, 0, peer_handshake_bytes - & gt; Length, SocketFlags: : None)) & lt; Peer_handshake_bytes - & gt; Length)
{
//SendFailed_MemClear (Mag_Handshake Mag_Handshake);//clear the Memory
return;
}
}
The catch (SocketException ^ se)
{
The Debug: : Write (" SocketException caught!!!!!! ");
The Debug: : WriteLine (Source: "" + se - & gt; The Source + "Message:" + se - & gt; Message);
}
The finally
{
Peer_Socket - & gt; Close ();
Peer_Socket=nullptr;
}

}
}

CodePudding user response:

The present network situation is such, often hundreds of peer can even on 4, 5
  • Related