build and test the NAT samples of raknet

来源:互联网 发布:java static内存泄漏 编辑:程序博客网 时间:2024/06/11 00:14

This article shows how to build and test the NAT samples of raknet.

Build the NAT samples of RakNet

  1. checkout the newest code of RakNet and miniupnp(which is depended by the RakNet/Samples/NATCompleteClient)
    1. git clone https://github.com/OculusVR/RakNet.git
    2. git clone git clone https://github.com/miniupnp/miniupnp.git
  2. build the miniupnp, using make cmd: in the directory of miniupnpc, such as in my pc: home/james/work/miniupnp/miniupnpc
    1. $su root
    2. $make and $make install
  3. build the NATCompleteClient Sample of RakNet:
    1. $cd RakNet/Samples/NATCompleteClient
    2. patch the main.cpp : (because the original main.cpp is based on the miniupnpc-1.6.20120410, which has some error)

      patch of main.cpp

      Icon

      diff --git a/Samples/NATCompleteClient/main.cpp b/Samples/NATCompleteClient/main.cpp

      index 9d1f632..6e19f1f 100644

      --- a/Samples/NATCompleteClient/main.cpp

      +++ b/Samples/NATCompleteClient/main.cpp

      @@ -252,7 +252,7 @@ struct UPNPFramework : public SampleFramework

                                      char leaseDuration[128];

                                      r = UPNP_GetSpecificPortMappingEntry(urls.controlURL,

                                              data.first.servicetype,

      -                                       eport, "UDP",

      +                                       eport, "UDP", 0, //jamesli^M

                                              intClient, intPort,

                                              desc, enabled, leaseDuration);

       

      lijian@lijian-dell:~/devdir/raknet/RakNet/Samples/NATCompleteClient$

    3.  $$g++ -m64 -g -pthread   -I./ -I./../../Source main.cpp -I/home/james/work/miniupnp/miniupnpc ./../../Source/*.cpp -lminiupnpc -o NATClient.exe
  4. Run and Test the NATClient.exe in two PC of Linux.
  5. Test Case:
    Set the two PC on behind of Routers, case 1) one same Routers, case 2) two different routers, case 3) one PC based vpn connection
  6. For any select items using the default value(push the "Enter" key), like this:

    Do you have a server running the NATCompleteServer project? (y/n):

  7. Set the first NATClient as listen, like this:

    Connecting...

    Enter RakNetGuid of the remote system, which should have already connected

    to the server.

    Or press enter to just listen.

  8. press enter, you will see like this:

    Listening

    My GUID is 1420533104223888

    Calculating port stride from 66.118.161.138|61111

     

  9. Set the second NATClient to connect the first client based its GUID: 1420533104223888

  10. you will see the test result like this:

 

The test Result

Icon

james@james-T420:~/work/RakNet/Samples/NATCompleteClient$ ./NATClient.exe 
Enter local port, or press enter for default: 
NAT traversal client
Supported operations:

UPNPFramework
Requires server: No
Description: Use UPNP to open the router

NatTypeDetectionFramework
Requires server: Yes
Description: Determines router type to avoid NAT punch attempts that cannot
succeed.

NatPunchthoughClientFramework
Requires server: Yes
Description: Causes two systems to try to connect to each other at the same
time, to get through routers.

Router2Framework
Requires server: No
Description: Connect to a peer we cannot directly connect to using the
bandwidth of a shared peer.

UDPProxyClientFramework
Requires server: Yes
Description: Connect to a peer using a shared server connection.

Do you have a server running the NATCompleteServer project? (y/n): 
Note: Only UPNP and Router2 are supported without a server
You may want to consider using the Lobby2/Steam project. They host the
servers for you.

Executing UPNPFramework

Failed UPNPFramework
Proceeding to next stage.
Executing NatTypeDetectionFramework

Failed NatTypeDetectionFramework
Proceeding to next stage.
Executing NatPunchthoughClientFramework
Enter IP of system NatPunchthroughServer, or press enter for default: 
Enter port of system NatPunchthroughServer, or press enter for default: 
Connecting...
Enter RakNetGuid of the remote system, which should have already connected
to the server.
Or press enter to just listen.
1420532102687679
Calculating port stride from 66.118.161.138|61111
HAS_PORT_STRIDE 0. First external port 21393. Second external port 21393.
Starting ID_NAT_PUNCHTHROUGH_REQUEST to guid 1420532102687679.
                                                       499524562: TESTING_INTERNAL_IPS: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 127.0.1.1|50000.

                                                       499524592: TESTING_INTERNAL_IPS: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 127.0.1.1|50000.

Send with TTL 2 to 219.142.14.122|50000
                                                       499524925: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50000.

                                                       499524955: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50000.

                                                       499524986: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50000.

                                                       499525016: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50000.

                                                       499525046: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50000.

                                                       499525077: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50000.

                                                       499525137: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50000.

                                                       499525198: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50000.

Send with TTL 2 to 219.142.14.122|50001
                                                       499525499: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50001.

                                                       499525530: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50001.

                                                       499525591: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50001.

                                                       499525651: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50001.

                                                       499525682: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50001.

                                                       499525742: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50001.

                                                       499525803: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50001.

                                                       499525833: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50001.

Send with TTL 2 to 219.142.14.122|50002
                                                       499526135: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50002.

                                                       499526196: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50002.

                                                       499526226: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50002.

                                                       499526286: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50002.

                                                       499526347: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50002.

                                                       499526378: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50002.

                                                       499526438: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50002.

                                                       499526499: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102687679, system address 219.142.14.122|50002.

Failed punchthrough once. Returning failure to guid 1420532102687679, system address 219.142.14.122|50000 to user.
Failed: ID_NAT_PUNCHTHROUGH_FAILED

Failed NatPunchthoughClientFramework
Proceeding to next stage.
Executing Router2Framework

Failed Router2Framework
Proceeding to next stage.
Executing UDPProxyClientFramework

Failed UDPProxyClientFramework
Connectivity not possible. Exiting

james@james-T420:~/work/RakNet/Samples/NATCompleteClient$ ./NATClient.exe

---------------------------------------------------------------------




lijian@lijian-dell:~/devdir/raknet/RakNet/Samples/NATCompleteClient$ ./NATClient.exe 
Enter local port, or press enter for default: 
NAT traversal client
Supported operations:

UPNPFramework
Requires server: No
Description: Use UPNP to open the router

NatTypeDetectionFramework
Requires server: Yes
Description: Determines router type to avoid NAT punch attempts that cannot
succeed.

NatPunchthoughClientFramework
Requires server: Yes
Description: Causes two systems to try to connect to each other at the same
time, to get through routers.

Router2Framework
Requires server: No
Description: Connect to a peer we cannot directly connect to using the
bandwidth of a shared peer.

UDPProxyClientFramework
Requires server: Yes
Description: Connect to a peer using a shared server connection.

Do you have a server running the NATCompleteServer project? (y/n): 
Note: Only UPNP and Router2 are supported without a server
You may want to consider using the Lobby2/Steam project. They host the
servers for you.

Executing UPNPFramework

Failed UPNPFramework
Proceeding to next stage.
Executing NatTypeDetectionFramework

Failed NatTypeDetectionFramework
Proceeding to next stage.
Executing NatPunchthoughClientFramework
Enter IP of system NatPunchthroughServer, or press enter for default: 
Enter port of system NatPunchthroughServer, or press enter for default: 
Connecting...
Enter RakNetGuid of the remote system, which should have already connected
to the server.
Or press enter to just listen.

Listening
My GUID is 1420532102687679
Calculating port stride from 66.118.161.138|61111
HAS_PORT_STRIDE 0. First external port 50000. Second external port 50000.
                                                       499524561: TESTING_INTERNAL_IPS: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 127.0.1.1|50000.

                                                       499524591: TESTING_INTERNAL_IPS: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 127.0.1.1|50000.

Send with TTL 2 to 219.142.14.122|21393
                                                       499524922: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21393.

                                                       499524952: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21393.

                                                       499524983: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21393.

                                                       499525013: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21393.

                                                       499525043: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21393.

                                                       499525103: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21393.

                                                       499525133: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21393.

                                                       499525193: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21393.

Send with TTL 2 to 219.142.14.122|21394
                                                       499525494: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21394.

                                                       499525524: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21394.

                                                       499525584: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21394.

                                                       499525645: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21394.

                                                       499525675: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21394.

                                                       499525735: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21394.

                                                       499525795: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21394.

                                                       499525825: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21394.

Send with TTL 2 to 219.142.14.122|21395
                                                       499526126: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21395.

                                                       499526186: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21395.

                                                       499526246: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21395.

                                                       499526276: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21395.

                                                       499526337: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21395.

                                                       499526397: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21395.

                                                       499526427: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21395.

                                                       499526487: TESTING_EXTERNAL_IPS_FACILITATOR_PORT_TO_FACILITATOR_PORT: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid 1420532102566828, system address 219.142.14.122|21395.

Failed punchthrough once. Returning failure to guid 1420532102566828, system address 219.142.14.122|21393 to user.
Failed: ID_NAT_PUNCHTHROUGH_FAILED

Failed NatPunchthoughClientFramework
Proceeding to next stage.
Executing Router2Framework

Failed Router2Framework
Proceeding to next stage.
Executing UDPProxyClientFramework

Failed UDPProxyClientFramework
Connectivity not possible. Exiting
^[[Alijian@lijian-dell:~/devdir/raknet/RakNet/Samples/NATCompleteClient$

 

Note:

if we have one server running NATCompleteServer,  which the two PCs could connect to it, we also test the NATCompleteServer:

build it: $g++ -m64 -g -pthread -I./ -I./../../Source main.cpp -I./../CloudServer ./../../Source/*.cpp ./../CloudServer/CloudServerHelper.cpp -o NATServer.exe

Or the NATClient will use the default test server: 66.118.161.138|61111, which is one public test server supplied by the OculusVR.

0 0
原创粉丝点击