Java Networking question for TCPIP client server echo program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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)

17th Dec 2022, 2:07 PM
Bhumi Batawale
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 }
13th Jan 2023, 9:13 PM
zemiak
0
Code?
26th Dec 2022, 8:29 PM
Vanessa Nilsson