Problems connecting to my computer using external ip

Asked

Viewed 695 times

1

I am trying to make a java application that will serve as a server so that an android application establishes a communication by Socket with the computer that my program is open on the port that it is listening to (I chose 50000). everything is all right:

  • a Forwarding port is configured on the router using the upnp protocol
  • the program is open and listening on the correct port ( it appears that the port 50000 is LISTENING, in the netstat command )
  • my external ip is solved on a host of the no-ip site, and when I ping to the host, the correct external ip appears
  • Currently, including the application can even connect and at first ( while my modem is 'happy' or something ) everything works, including external networks and everything seems ok.

but after a few hours with the program running the computer magically becomes inaccessible. I checked all possible (will it really be all?) causes

  • no change of IP
  • the door remains accessible ( I tested on various websites that check whether the doors are open )
  • I can ping to my host and it still directs to the correct external ip...
  • the application can still connect if the host ip is used (192.168.1.8)

but things get complicated when I try telnet:

  • telnet to 192.168.1.8 50000 works (host local)
  • for 127.0.0.1 50000 also works (also local host?)
  • for localhost 50000 also works (obviously host local)
  • but for the external ip, nor modem ip (192.168.1.1) no, says so:

"Connecting to 177.203.28.xxx.... could not open connection with host, on port 50000: connection failed" and the telnet at the modem address, also does not work (I think it should work since the port is forwarded) including telnet without specifying the port of the same message... (when everything is working, the telnet command without specifying port connects to my modem and asks to put a user and password)

the java code of the server that opens Serversocket looks like this:

@Override
public void run()
{
    try {
        Inicie();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        Inicio.Erro("Erro no Server:"+e.getMessage());
        e.printStackTrace();
    }
    System.out.println("SocketServerThread Parou");
    Inicio.LOG("Server Parou");
}   
public void Inicie() throws InterruptedException
{
    connect();

    while(KeepWaiting)
    {
        WaitClient();
    }
} 
public void connect()
{
    try {
        //  serverSocket = new ServerSocket(50000);
            serverSocket =new ServerSocket(50000);//,0,InetAddress.getByAddress(new byte[]{(byte)172,0,0,1}));
            System.out.println("Socket Servidor Pplware");
            System.out.println("A escuta na porta:\n"+InetAddress.getLocalHost()+":"+serverSocket.getLocalPort());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
}
public void WaitClient() throws InterruptedException{
    try {
            Inicio.LOG("Aguardando Conexao...");
            Socket socket = serverSocket.accept(); // blocking wait ( 99.9999% of the time in this line )
            BufferedReader buff_Reader = new BufferedReader(new InputStreamReader(socket.getInputStream(),Charset.forName("UTF-8")));
            BufferedWriter buff_Writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),Charset.forName("UTF-8")));
            System.out.println("<Conectou>");
            System.out.println("IP Cliente: " + socket.getInetAddress());
            Inicio.LOG("Conectou -> IP Cliente: " + socket.getInetAddress());
            ReadThread reader_thread = new ReadThread(buff_Reader);
            WriteThread writer_thread = new WriteThread(buff_Writer);
            ConexaoCliente nova = new ConexaoCliente(this,reader_thread,writer_thread,socket);
            Conexoes.add(nova);
            System.out.println("Conexões atuais:"+Conexoes.size());
            nova.start(); // starta a thread que mantem a conexão com aquele cliente
        } catch (IOException e ){//SQLException e) {
            System.out.println("<Erro>");
            Inicio.Erro("Server Parou com Erro:"+e.getMessage());
            e.printStackTrace();
            KeepWaiting=false;
        }
        finally{

        }
}

the code in the android application establishing the connection by Socket is like this:

   @Override
public void run()
{
    try {
        connect();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
public void connect() throws InterruptedException
{
    try {
        exaustive_connect();
        if(connection.isConnected()&&Continuar) {
            BufferedReader buff_reader = new BufferedReader(new InputStreamReader(new myInputStream(connection.getInputStream()), Charset.forName("UTF-8")));
            BufferedWriter buff_writer = new BufferedWriter(new OutputStreamWriter(new myOutputStream(connection.getOutputStream()),Charset.forName("UTF-8")));
            Reader = new ReadThread(buff_reader);
            Writer = new WriteThread(buff_writer);
            Comunicar(); // método que escuta e envia mensagens usando esse Reader e Writer.
        }
        else
        {
            ManageConection.E("ConexaoServidor","Não foi possivel conectar");
        }
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally{
        close(); // método que fecha o socket, o Reader e Writer
    }

}
private void exaustive_connect()
{
    try {
        if(!exaustive_tryconn(500))
        {
            if(!exaustive_tryconn(2000))
            {
                if(!exaustive_tryconn(5000))
                {
                    ManageConection.LOG("Não conseguiu");
                }
            }
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}
private boolean exaustive_tryconn(int timeout)
{
    connection = new Socket();
    try {
        connection.connect(new InetSocketAddress(ManageConection.IP, ip_holder.port), timeout); // tenta um host
    } catch (Exception e) {
        e.printStackTrace();
    }
    if(connection.isConnected())return true;
    connection = new Socket();
    try {
        connection.connect(new InetSocketAddress(ManageConection.IP2, ip_holder.port), timeout); // tenta um segundo host
            } catch (Exception e) {
        e.printStackTrace();
    }
    return connection.isConnected();
}

so I’m here perplexed trying to find some solution to this. I’ve searched almost half the Web, some say the problem may be ISP, Firewall, NAT, upnp bugged, Proxy with connection blocking....

but I just don’t know how to check these things, others don’t even know what they mean....

what really worked so far was restarting the modem and things go back to normal... but this makes the server stay 5 to 10 minutes offline, because the dynamic dns of the no-ip takes a while to stay up to date, besides what my modem takes about 3 minutes to get back to the internet connection after restarting it. I’m almost sure that there is a way to solve this without having to manually interfere, after all this has to stay at least one night on direct, since it will be a delivery system of lunches.

I’m sorry to specify so many things, but I think even detailing as much as I can is still going to be hard to figure out what might be going on, I’m still kind of 'layman' when it involves internet communication.


including I tried several internet access checks, including this: http://ping.eu/port-chk/ where I test the host and port, and my program even detects that there was a connection... then if the server of this site can connect to my program remotely.... because a telnet doesn’t work?

  • Are you doing this on a personal computer? if you rule out proxy (unless the external address is an organization). is using only the modem? or has a router connected to it?

  • yes I am doing on a personal computer, the address is of my modem/ router, n I can tell the difference only has a device here TG 580, I think q is a kind of "modem routable" that in addition to convert the signal also makes the sharing.

1 answer

0


Unfortunately the Suport port remapping of UPNP technology is stopped because most routers do not perform this operation.

Several serious flaws justify this, however it should always take into consideration that if each android phone could serve as server file exchange applications (mainly pirates) would increase a lot.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.