Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a server with dynamic external IP-address. How to create a connection on the internet ? After that, the client, knowing external IP-address, has to connect.

What I have tried:

C#
UPnPNAT upnpnat = new UPnPNAT();
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 
            IPAddress ipAddress = null; 
            IPEndPoint Addr = null; 
            NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection;
            mappings.Add(20131, "TCP", 20131, "46.175.163.14", true, "Test Open Port");
            Addr = new IPEndPoint(IPAddress.Parse("192.168.0.111"), 20131); //"localhost" = 127.0.0.1

            s.Bind(Addr);

            s.Listen(10);
Posted
Updated 25-Feb-16 1:30am
v2

The client will have to know the address. I suggest you change your dynamic one for a static one. Otherwise, put the ip address in a config file and then update that each time it changes so you don't have to recompile the code every time.
 
Share this answer
 
Besides the solution posted by Ryan you can use a Dynamic DNS - Wikipedia, the free encyclopedia[^] service. Most internet routers and modems provide an option to pass their dynamic IP address to such a service when it has changed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900