package cn.itcast.test; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Server { public static void main(String[] args) throws Exception { ServerSocket socket = new ServerSocket(9999) ; Socket accept = socket.accept() ; InputStream inputStream = accept.getInputStream() ; BufferedReader buf = new BufferedReader(new InputStreamReader(inputStream)); PrintWriter pw = new PrintWriter(accept.getOutputStream() , true) ; String line = null; while((line = buf.readLine()) != null){ byte[] bytes = line.getBytes() ; reverseArr(bytes); pw.println(new String(bytes )); } accept.close() ; socket.close() ; } public static void reverseArr(byte[] arr){ for(int x = 0 , y = arr.length - 1 ; x <= y ; x++ , y--){ byte temp = arr[x]; arr[x] = arr[y] ; arr[y] = temp ; } } } |