+ 1
Java Networking question for TCPIP client server echo program
Errors faced in client side program are java.net.ConnectException: Connection refused: connect Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.DataInputStream.readLine()" because "this.input" is null at Client.<init>(Client.java:44) at Client.main(Client.java:68)
2 Answers
+ 1
if you run client separately, without server,
attempt to connect non-existent ServerSocket
socket = new Socket(address, port);
throws IOException
java.net.ConnectException: Connection refused
then after catch it tries
line = input.readLine();
but the input is null because it threw Exception
before the input Initialisation
input = new DataInputStream(System.in);
to avoid NullPointerEx. do:
catch(IOException i) {
System.out.println(i);
return; // added
}
0
Code?