简体   繁体   中英

Can only access to my server through “localhost”

I am programming a trading-game, that requires multiplayer. I realized, that my client can only access through "localhost" on the pc the server is running on. How do I figure out if the server is online, so I know if is the firewall or something else? If someone already knows the solution I would be even happier.

Thanks!

edit: My operating system is Windows 7.

Update: I managed to connect to my server on the same computer with two Addresses i found through ipconfig. One that my rooter assinged to me and I don't know were the other one comes from. First I tried the one I found through searching "what is my IP" on Google, wich did not work. I still can't connect to the server through other pc's connected to the same router(fritz-box).

    Server:

    ExecutorService executor = Executors.newFixedThreadPool(100);       

    ServerSocket server;        
    try {               
        server = new ServerSocket(5555);    
        System.out.println("Server gestartet");

        while(true){
            Socket client = server.accept();
            executor.execute(new ClientHandler(client));                
        }           

    }catch (Exception e) {
        e.printStackTrace();
    }       
}

    Client:

    try {
            InetAddress addr = InetAddress.getByName("MY IP");                                  
                //Works
                client = new Socket("localhost",Port);
                //Does not work
                client = new Socket(addr,Port);
                //Does not work
                client = new Socket("MY IP",Port);

                System.out.println("Client gestartet");

                //Streams           
                out = client.getOutputStream();
                writer = new PrintWriter(out);

                in = client.getInputStream();
                reader = new BufferedReader(new InputStreamReader(in));
                // ------------------------------------------------         

                String s = null;                    
                while((s=reader.readLine())!=null){
                    render(s);
                }               
            } catch (IOException e) 
            {
            e.printStackTrace();
            }

I left the ClientHandler out, because I am sure there is not the Problem.

If it's a firewall problem you will get a connect timeout. If you get 'connection refused', the server isn't running.

Do not modify your ServerSocket construction as suggested elsewhere here. The way you're doing it is correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM