tags:

views:

880

answers:

3

I want to do TCP Hole Punching (NAT Traversal) in C#. It can be done with a rendevouzs server if needed. I found http://sharpstunt.codeplex.com/ but can not get this to work. Ideally i need some method which i give a PortNumber (int) as parameter that after a call to this method is available ("Port Forwarded") at the NAT. It would be also ok if the methode just returns some port number which is then available at the NAT. Has anybody done this in C# ? Can you give me working examples for sharpstunt or something else?

Thank you

A: 

I am not familar with your topic, but I happen to know an open source P2PVPN, which uses a lib to do NAT. You may check it here (www.SocialVPN.org).

Good luck.

Ying
+1  A: 

http://sipsorcery.codeplex.com has a working stun server.

SipSorcery.core -> SipSorcery.Net -> Stun

jgauffin
i would love to have STUNT not STUN but thanks it might be a starting point
I think it has both. stunt is just stun over TCP, right?
jgauffin
stunt is stun but with TCP instead of UDP. You cannot just replace UDP with TCP and it works like magic. Unfortunatly SipSorcery.core -> SipSorcery.Net -> Stun does NOT provide STUNT...
There's no TCP hole punch, it's a UDP hole punch.
Pavel Radzivilovsky
+2  A: 

It sounds like you might be getting TCP and UDP mixed up. TCP is a connection-orientated protocol, easily understood by firewalls and routers, and requires one initiator (client) and one listener (server). If both client and server are behind firewalls or NAT, you cannot punch a hole through without having them both connect to some proxy server (which is not firewalled). The problem with this is that then the proxy would be responsible for relaying all of their traffic.

From your question, it sounds like you are more interested in UDP hole punching, which exploits the fat that UDP is stateless, and not connection-orientated. Therefore most state-tracking firewalls will make a "best guess" about the UDP data flow, and assume that traffic leaving on a given port will receive replies on the same port, and automatically route them back. If, using some out-of-channel means (such as a TCP server which simply passes addresses and not data), both peers can be transmitting data to each other on the same ports, their respective firewalls/NAT routers will open up holes allowing the traffic in.

As for how to do it, it all depends on how you are going to get the IP address of the peers to each other. Once you have it, simply start transmitting UDP packets on an agreed port, and wait for a reply.

Tyr
I can do UDP Hole punching which is nown as STUN its quite easy.BUT you can do TCP Hole punching, it is just more complex and called STUNT (last T is for TCP). http://sharpstunt.codeplex.com/ claims do be able to do it but i cant get it to work. There are also some JAVA libs that do it...