leithdm
4/13/2020 - 7:35 AM

[Socket, InputStreamReader(socket.getInputSteam()), BufferedReader(InputStreamReader)] and [Socket, PrintWriter(socket.getOutputStream())] /

[Socket, InputStreamReader(socket.getInputSteam()), BufferedReader(InputStreamReader)] and [Socket, PrintWriter(socket.getOutputStream())] // Read/Write from a Server

//Establishing a connection to the server, then reading from server
Socket readingSocket = new Socket("127.0.0.1", 5000); 
InputStreamReader stream = new InputStreamReader(readingSocket.getInputStream()); 
BufferedReader reader = new BufferedReader(stream); 
String message = reader.readLine(); 

//Different scenario; here we are writing to server
Socket writingSocket = new Socket("127.0.01", 5000); 
PrintWriter writer = new PrintWriter(writingSocket.getOutputStream()); 
writer.println("message to send");