public static void main(String[] args) throws UnknownHostException, Exception { // TODO Auto-generated method stub
Socket socket=new Socket("192.168.1.101",10009); BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); BufferedReader bfr=new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedWriter bfw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); String line=null; while((bf.readLine())!=null){ bfw.write(line); bfw.newLine(); bfw.flush(); String len=bfr.readLine(); System.out.println(len); } socket.close(); bf.close(); }
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
ServerSocket serverSocket=new ServerSocket(10009);
Socket socket=serverSocket.accept();
System.out.println(socket.getInetAddress().getHostAddress());
BufferedReader bfr=new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter bfw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
String line=null;
while((line=bfr.readLine())!=null){//阻塞 没发现回车标记还在等着读
bfw.write(line.toUpperCase());
bfw.newLine();
bfw.flush();
}
serverSocket.close();
socket.close();
}
|
|