Hello guys! Basically I need to know how to make the client receive multiple lines from the server. In my code it only reads the first line.
Server:
public class Server { public static void main(String[] args) throws Exception { Server SERVER = new Server(); SERVER.run(); } public void run() throws Exception { ServerSocket SRVSOCK = new ServerSocket(4444); Socket SOCK = SRVSOCK.accept(); InputStreamReader IR = new InputStreamReader(SOCK.getInputStream()); BufferedReader BR = new BufferedReader(IR); PrintStream PS = new PrintStream(SOCK.getOutputStream()); PS.println("Message 1" + "\n" + "Message2");//*bounces the message back to the client! } }
Client:
public class Client { public static void main(String[] args) throws Exception { Client CLIENT = new Client(); CLIENT.run(); } public void run() throws Exception { Socket SOCK = new Socket("localhost",4444); PrintStream PS = new PrintStream(SOCK.getOutputStream()); //* from client to server InputStreamReader IR = new InputStreamReader(SOCK.getInputStream());//*from server to client BufferedReader BR = new BufferedReader(IR); String MESSAGE = BR.readLine(); System.out.println(MESSAGE);//*display what is received from the server } }
I am new to java so any help is appreciated! Thanks guys!