i am trying out this code that i got from one of suns tutorials, it deals with echoing an input back to the command prompt.
this is where i got the code
http://java.sun.com/docs/books/tutorial/networking/sockets/readingWriting.html
this is my code, and i am getting the message "Couldn't get I/O for the connection to: 127.0.0.1" printed on the screen.. i think that i might have made a mistake while editing the hostname and port name, please look in to this and help me with the working code ..
import java.io.*;
import java.net.*;
public class EchoClient {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket("localhost",7);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
} catch (UnknownHostException eoo) {
System.err.println("Don't know about host: 127.0.0.1");
System.exit(1);
} catch (IOException eo) {
System.err.println("Couldn't get I/O for the connection to: 127.0.0.1");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("echo: " + in.readLine());
}
out.close();
in.close();
stdIn.close();
echoSocket.close();
}
}