{ Socket s = new Socket("xxx.xx.xx.xx",10004);
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
BufferedReader bufIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line = null;
while((line=bufr.readLine())!=null){
if("over".equals(line))
break;
out.println(line);
String upperStr = bufIn.readLine();
System.out.println(upperStr);
}
s.close();}
so does the out.println(line); mean 1. the string which was entered will appear on the screen and 2.the content will be sent to the server socket at the same time? Thanks, guys.
Your variable
outis aPrintWriter, but that doesn’t mean that its something that will be printed on the screen. In this case, you gave it something that is the output stream of a socket, so it will print a line to the socket. If you want it to appear on the screen as well, you’ll have to call something likeSystem.out.println(line)as well.