Simple Socket IOstream problem
ok, I decided to start trying to network for the first time, so I looked up the tutorial and tried out some of the code. I kept running into the IOException that was thrown. I tried to fix it and eventually i just copied and pasted the code into my compiler and I still get the same error caught.
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("Alexs-Computer.local", 4321);
//echoSocket = new Socket("Alexs Computer", 4321);
//echoSocket = new Socket(InetAddress.getLocalHost.getHostName, 4321);
//echoSocket = new Socket("10.0.1.5", 4321);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection");
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();
}
}
It runs into the IO exception so outputs "Couldn't get I/O for the connection"
Can anyone help me out? Im just trying to get it to run so I can move on!