WinSock and NATs

Started by
20 comments, last by Evil Bill 21 years, 8 months ago
Yup, its me again... I''ve finally got everything figured out, and it works great. The only problem is with NATs (Network Address Translators). I am on a home network, with 3 computers. Fortunately, i''m the computer with the net connection. The problem comes when i try to use my chat program (prrrfftt! if you can call it a chat program) on my sisters computer. We use windows internet connection sharing, so she can connect to the internet through my computer. The only problem with this, is that my program can only connect to the network, it isn''t aware of the interent connection sharing. So, on to the question: Is there any way to get the IP of a computer on the other side of a NAT? E.g. can i get my sisters internet IP? At the moment i use gethostbyname(NULL) to get the IP addresses of the current computer. How do most games / apps handle this? Thanks for all the help guys, Steve Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
Advertisement
Are youi trying to originate your connection from inside or outside of the NAT?

Stephen Manchester
Senior Technical Lead
Virtual Media Vision, Inc.
stephen@virtualmediavision.com
(310) 930-7349
Stephen ManchesterSenior Technical LeadVirtual Media Vision, Inc.stephen@virtualmediavision.com(310) 930-7349
Either.
At the moment i''m trying to connect to my friends computer (which is behind a router) from my internet connection.

Lets just assume i have no NAT on my side just now (because its not in use at the moment).

Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
The only way to connect to a machine that is behind a NAT is to have them configure it for forwarding. The NAT device will then forward all requests it gets to for a particualr port to the specified machine. The machine can then handle it.

When you connect though, you specify the NAT device address, not the internal machine address. The internal machine is using an illegal addres that internet routers will not forward.

are you using TCP or UDP?

Stephen Manchester
Senior Technical Lead
Virtual Media Vision, Inc.
stephen@virtualmediavision.com
(310) 930-7349
Stephen ManchesterSenior Technical LeadVirtual Media Vision, Inc.stephen@virtualmediavision.com(310) 930-7349
I''m using TCP.

So theres no way to just pretend it isn''t there?

How do other games do it?

Cheesr, Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
if your friends computer is behind a NAT then the only way you can connect to them is if they have that NAT set up to route your particular application port to their machine. otherwise you are out of luck.

the way chat programs work is that everyone is aware of the central server''s IP address. when you log onto AIM or whatever, you make a listen connection out to the main server. when you send a message, you send to the server and then the server sends your message down your friends listen connection. i imagine that every message you send has some sort of id number associated with it that the server uses to send a message out the correct pipe.

NATs are used as dumb firewalls b/c they by default don''t route any incoming data to any of the internal computers unless they are speciffically told to route a certain port to a certain machine. you may be able to config the NAT to broadcast all incoming data on a specific port to all the machines inside, but i''m not sure about that. my NAT box doesn''t allow that.

basically you need a central server that is not behind a NAT to control everything.

-me
You can initiate a connection from inside a NAT device if your going to a legal address. UDP sometimes doesn''t work this way but TCP always does. Game servers have legal addresses so they can be connected to.

It''s trying to get into a NAT network that is the hard part. Getting out is easy.
Stephen ManchesterSenior Technical LeadVirtual Media Vision, Inc.stephen@virtualmediavision.com(310) 930-7349
quote:Original post by Evil Bill
How do other games do it?


incedentally games do it the same as chat progs w/ a central server. that''s why you can''t host a game server unless you are either outside of a NAT or have opened all the proper ports on the router to go to your machine.

trying to set up your NAT to route ALL the proper game ports to your machine can be a nightmare.

-me

Ah, bollocks .
I''ve been looking through past topics, and they all seem to say the same thing.


Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
Jeez, my inbox is filling up with all these replies!

quote:
It''s trying to get into a NAT network that is the hard part. Getting out is easy.

I set it up so my friend (behind the router) was the client, trying to connect to me, and that didn''t work? All ive been able to test at the moment is across my home network. I''m hoping to test it over modem to another friend soonish.

Cheers, Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)

This topic is closed to new replies.

Advertisement