- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- public class ClientDemo2 {
- public static void main(String[] args) throws IOException {
- Socket s = new Socket("192.168.1.101", 10010);
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- PrintWriter pw = new PrintWriter(s.getOutputStream(), true);
- String line = null;
- while((line = br.readLine()) != null)
- {
- if("over".equals(line))
- break;
- pw.println(line);
- pw.flush();
- }
-
-
- BufferedReader br1 = new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintWriter pw1 = new PrintWriter(System.out, true);
- String newLine = null;
- while((newLine = br1.readLine()) != null)
- {
- pw1.println(newLine);
- pw1.flush();
- }
- pw1.close();
- br.close();
- s.close();
- }
- }
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.ServerSocket;
- import java.net.Socket;
- public class ServerDemo2 {
- public static void main(String[] args) throws IOException {
- ServerSocket ss = new ServerSocket(10010);
- Socket s = ss.accept();
- BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintWriter pw = new PrintWriter(s.getOutputStream());
- String line = null;
- while((line = br.readLine()) != null)
- {
- pw.println(line.toUpperCase());
- pw.flush();
- }
- pw.close();
- s.close();
- }
- //输入over以后,能够转成大写,但是程序并没有结束,这是为什么?
复制代码 |