Olá pessoal, hoje estava fazendo um exercício do livro Head First Java, ai apareceu o seguinte código:
[code]import java.io.;
import java.net.;
public class DailyAdviceClient {
public void go() {
try {
Socket s = new Socket("127.0.0.1", 5000);
InputStreamReader streamReader = new InputStreamReader(s.getInputStream());
BufferedReader reader = new BufferedReader(streamReader);
String advice = reader.readLine();
System.out.println("Today you should: "+advice);
reader.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
DailyAdviceClient client = new DailyAdviceClient();
client.go();
}
}[/code]
Mas ai apareceu os seguintes erros:
[quote]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.(Unknown Source)
at java.net.Socket.(Unknown Source)
at atividades.headfirst5.DailyAdviceClient.go(DailyAdviceClient.java:10)
at atividades.headfirst5.DailyAdviceClient.main(DailyAdviceClient.java:28 )[/quote]
Gostaria da ajuda de vocês para tentar entender o que pode estar acontecendo. Obrigado