我正在使用一个简单的程序连接到服务器:
就这个:
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)
可能是什么问题呢?