fych / P2P-Over-MiddleBoxes-Demo

A simple demo of P2P communication over middle boxes such as NAT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

P2P-Over-MiddleBoxes-Demo

A simple demo of P2P communication over middle boxes such as NAT

compile:

make

run:

./server host port

./client
>>> help

FAQ

It doesn't work

UDP hole punching works only if both of the peers' NAT types are Cone NAT.

How to check whether my NAT is cone NAT

There're tools for manually check the external NAT's type in tools. For example:

    1. cd tools && make
    1. run tools/udp_server 2222 and tools/udp_server 3333 on your public server.
    1. run tools/udp_client on your client
    1. (udp_client) sendto server:2222 text
    1. (udp_client) sendto server:3333 text
    1. check your server output to see the output.

example server output:

$ ./tools/udp_server 3333
UDP bind on 0.0.0.0:3333
recv 4 bytes from [172.16.47.71:14781]: text
$ ./tools/udp_server 2222
UDP bind on 0.0.0.0:2222
recv 4 bytes from [172.16.47.71:14781]: text

For cone NAT, the from part should be the same.

My NAT is cone NAT, but it still doesn't work

If your two peers are behind the same NAT, this NAT must support LOOPBACK TRANSMISSION to forward messages. You can test it by using the utils(udp_server/udp_client) in tools

related post (in Chinese)

About

A simple demo of P2P communication over middle boxes such as NAT


Languages

Language:C 96.1%Language:Makefile 3.9%