本帖最后由 洋葱骑士 于 2014-3-13 20:53 编辑
try{ ServerSockets = new ServerSocket(8189); Socketincoming = s.accept(); try{ InputStream inStream = incoming.getInputStream(); OutputStream outStram = incoming.getOutputStream(); Scanner in = new Scanner(inStream); PrintWriter out = new PrintWriter(outStram,true); //out.println("Hello");//不加这一句,输入的第一行文字乱码? boolean done =false; while(!done && in.hasNext()){ String line = in.nextLine(); out.println("Echp:"+line); if(line.trim().equals("BYE")) done = true; } } finally{ incoming.close();//关闭连接 } } Catch(Exception e){ e.printStackTrace(); }
|