WinSocking: router problems?

Hey!

I've managed to create a basic LAN-program that sends and recv's data between my 2 home computers.

However if i would like to make a program that sends and recv's between my computer and my friends, would it (In theory) work basically the same way if he gives me his IP-address and i give him mine?

That is me making my computer a server.

Or is it more complicated, like will my router get me into trouble?

Yes, router will make it more complicated.

What you will need is called "port fowarding" - setting on router where you can specify that all incoming connections on port A must be forwarded to your computer on internal network on port B (can be same number as port A).

This way if somebody connects to your public IP address (what router has) on port A, then router will make sure to connect it to internal computer on port B.

But your program won't need any changes. All you need it updating this router setting on side which will be listening ("server") and your program should be able to connect.

There are more advanced techniques, like NAT hole punching, but it is not guaranteed to work (depends on your ISP and router). There is also UPNP protocol that allows server application to ask router to forward port automatically, but that is huge security risk - in any decent network environment it should be turned off.

Other than that hosting a 3rd party relay server outside of both of your home networks is another solution. This way traffic will always go through accessible server on network, regardless of router configuration.


Edited by Mārtiņš Možeiko on

Allright, thanks!

Do you know of any sources/tutorials that handle this part of networking?

Does Beej's go over it?


Replying to mmozeiko (#29468)

Which part? Port forwarding? That's is in your router's manual, not related to networking api's.


Replying to C_Worm (#29470)

Ah okay got it, ty!


Replying to mmozeiko (#29471)