publicstaticvoidmain(String[]args)throwsIOException{SocketechoSocket=null;PrintWriterout=null;BufferedReaderin=null;try{echoSocket=newSocket("localhost",1111);out=newPrin...
public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader in = null; try { echoSocket = new Socket ( "localhost", 1111); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: localhost."); System.exit(1); } System.out.println(in.readLine()); System.out.println(in.readLine()); String userInput = "ahfpd"; out.println(userInput); while(true) { try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } //隔一段时间} System.out.println(in.readLine()); } }}
一个简单的客户端程序,想让输出语句一直输出直到程序关闭时跳出,现在只能输出一次就不输出了,求教怎么改。
展开