Jump to content
  • Advertisement
Sign in to follow this  
alexus

NAT Punch How To?, need help in VB 2005

This topic is 4307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Ok I searched every where and cant reaaly find the code for nat punch, only the theory! Does any one knows how to do this in VB. net (2005)? im using System.Sockets class Thanks!

Share this post


Link to post
Share on other sites
Advertisement
You can take any sockets code, such as the code in my article, and translate it to the socket class. It's not really that different from the C version.

I know of no working implementation using Visual Basic, though.

Share this post


Link to post
Share on other sites
:-(
I dont have C compiler, im running VB Epress Edition

I juess there is no vb implementation because VB socket class returns the port # that is original one and not the one that router assigned :-(

Is it possible to compile your C code to a dll and use it as service file to just get the addresses?

I havent used C since version 4 im even efraid to edit it when I get my compiler installed

Share this post


Link to post
Share on other sites
Quote:
VB socket class returns the port # that is original one and not the one that router assigned


Not true. The library will use the port that is in the packet it receives, when you call something like recvfrom(). However, if your traffic doesn't actually go through the router, then there will be no translation (such as when testing on a local net). Also, some routers will assign the same port as on the inside socket, if that port is available.

Quote:
old C compiler


Visual C++ Express Edition is a free download from Microsoft. Make sure you also download and install the Platform SDK to get all the Win32/WinSock programming goodness.

Share this post


Link to post
Share on other sites
ok yes thats what i assume and the way most packets work that it should have return adress stated rather then general assumed address. But my knowlage of socket calss in VB is like 1% i just found about it last week, and i have no experiance in network programing (thats if we exclude DB apps which are not really network programing)

As to C++ Extress Edition I didntk now it exist, but even if i download it, i will feal like im lost, i havent seen the C code for years...

Oh yea could it be that VB cant read the masked port #?

Share this post


Link to post
Share on other sites
No, VB is no different from any other language running on the system.

I'm assuming you're talking about VB.NET. If so, it uses the same class that you'd use in C# or C++/CLR. Just read the documentation for the class on MSDN; it's all in there.

System.Net.Sockets.Socket on MSDN.

Share this post


Link to post
Share on other sites
ok, i found the error in my code so now i am getting the real remote port BUT when im sending back something to that port i'm getting errro saying host no ready or dosnt accept the the packats.

Why that? Could that be due to TCP or soemthing else?

Share this post


Link to post
Share on other sites
Ok i did some testings and it dosnt make any sense for me... Here are my observations:

My Setup: Laptop w. IP 192.168.1.197 is behind a NAT device which in not UPnP.
Desctop is not on the nated subnet and is "before" the router, its IP is 192.168.101 and it functions as the server for me to find out the port of laptop to send back the socket in that was that I dont need to configure the routher. Oh router IP 192.168.1.1 (Will consider this as WAN address) Finally defult port for my app is 5124

So...
1) Laptop send to 127.0.0.1:5124 - same app says recived from 127.0.0.1:3315
Sending socket to 127.0.0.1:3315 => Got error no such host or EndPoint not ready

2)Latop sending to Desctop to 192.168.0.101:5124 ... on desctop recived from 192.168.0.100:50710
3) Desktop sending to Laptop on just recived port # to 192.168.0.100:50710 => No host, ok fine
4) Repeating step 3 but with standard port to 192.168.0.100:5124 => No Host

Conclusion: Dosnt work!

What can I do here?
Put my Laptop into DMZ?


Share this post


Link to post
Share on other sites
You will need to draw a diagram of your network. How come your desktop has 192.x addresses, when you claim it's outside the NAT router, for example? (and you forgot a dot in that address).

What is the external address of the NAT router, btw? Or is what you listed the external address? Then what is the internal address? It would be less confusing if you numbered your external (but still internal?) net using a different number range, like 10.x.

Last: when sending to 127.0.0.1, NAT is not involved. I believe your problem might be that you don't use htons() correctly on the port ID, perhaps?

Example network for testing NAT:


Internet <--> 20.30.40.50 [NAT Router A] 10.0.0.1
|
192.168.0.1 [NAT Router B] 10.0.0.2 <---> 10.0.0.3 [Your Desktop]
|
192.168.0.2 [Your Laptop]


20.30.40.50 is actually your ISP-assigned public IP address.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!