Jump to content


Check out our Community Blogs



Recent Status Updates

View All Updates

Photo
- - - - -

Client cannot connect to server when outside of LAN

client server remote access

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 xXAlphaXx

xXAlphaXx

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 109 posts

Posted 02 June 2016 - 10:18 PM

So I am working on a pair of applications that work quite well when working on the internal LAN - even when I deploy the server application on the proper sever machine but I cannot seem to get the client to connect to the server when I am trying to connect outside of the LAN. On the remote server, I run netstat -an on the command prompt to see if I can see that the program is listening to the connection and I do see my program listed, however it looks like it is listing an internal IPv6 address which I found a bit odd. I checked what IP address my client side is attempting to connect to and it is the valid IPv4 address of my server. I suspect it has something to do with differences in IPv4 and v6 but I am not sure how to correct this.

 

I have checked that the ports are open on firewall/router. Everything was successful when testing port 80, but external services cannot see that the port is open when testing for my application.

 

(I have removed the website name on the client for privacy reasons, but I can confirm that it does resolve to the proper external IPv4 address)

 

Server Side

            IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            IPEndPoint localEndpont = new IPEndPoint(ipAddress, 9999);

            //Create Socket
            Socket listner = new Socket(SocketType.Stream, ProtocolType.Tcp);

            try
            {
                //Bind the socket to this local machine
                //Listen for a connection
                listner.Bind(localEndpont);
                listner.Listen(10);

                //Wait until connection is recieved
                Console.WriteLine("Waiting on client connection");
                Socket handler = listner.Accept();

Client Side

                IPHostEntry ipHostInfo = Dns.GetHostEntry("hostname.com");
                //IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress ipAddress = ipHostInfo.AddressList[0];
                IPEndPoint remoteEP = new IPEndPoint(ipAddress, 9999);

                

                //Create Socket
                Socket sender = new Socket(SocketType.Stream, ProtocolType.Tcp);

                try
                {
                    Console.WriteLine("Attempting to connect to server");
                    sender.Connect(remoteEP);

Attached Thumbnails

  • Capture.PNG

Edited by xXAlphaXx, 02 June 2016 - 10:20 PM.


#2 xXAlphaXx

xXAlphaXx

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 109 posts

Posted 02 June 2016 - 10:47 PM

Aha. Looks like I was right. I tinkered around with the fields in ipHostInfo.AddressList[] and found an entry for the internal IPv4 ip. That allowed everything to connect as needed.