0

我正在使用一个简单的程序连接到服务器:

就这个:

    public static void main(String[] args) throws Exception {
        String sentence;
        String modsent;

        //input Stream
        BufferedReader fromclient = new BufferedReader(new InputStreamReader(System.in));
        //client Socket
        Socket clientsock = new Socket("stockholm.serverdhse2.se", 9000);
        //output Stream attached to socket
        DataOutputStream serverout = new DataOutputStream(clientsock.getOutputStream());
        //input from Server
        BufferedReader fromserver = new BufferedReader(new InputStreamReader(clientsock.getInputStream()));

        sentence = fromclient.readLine();

        serverout.writeBytes(sentence + "\n");

        modsent = fromserver.readLine();

        System.out.println("From Server: " + modsent);

        clientsock.close();
    }

}

但现在我得到了例外:

Exception in thread "main" java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at register.main(register.java:22)

可能是什么问题呢?

4

1 回答 1

1

也许它只能通过网络中的范围 dns 服务器访问,请使用 nmap 进行检查:

nmap -A 斯德哥尔摩.serverdhse2.se -p 9000

给我一个:

无法解析给定的主机名/IP:stockholm.serverdhse2.se。

要确保它是一个 dns 问题,请尝试使用 ip。如果与您获得的 ip 成功连接:“dns 问题”

于 2012-10-05T08:16:50.670 回答