- public class ClientText {
- /*
- 服务端读取客户端键盘录入的信息,并将其转成大写。
- */
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- Socket s = new Socket("192.168.XXX.XXX",10005);
-
- BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
-
- BufferedWriter bufout = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
-
- BufferedReader bufrin = new BufferedReader(new InputStreamReader(s.getInputStream()));
-
- String line = null;
- while((line=bufr.readLine())!=null)
- {
- if("over".equals(line))
- break;
- bufout.write(line);
- bufout.newLine();
- bufout.flush();
-
- String str = bufrin.readLine();
- System.out.println("服务端说:"+str);
- }
- s.close();
- bufr.close();
- }
- }[code]class ServerText
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss = new ServerSocket(10005);
-
- Socket s = ss.accept();
-
- BufferedReader bufrin = new BufferedReader(new InputStreamReader(s.getInputStream()));
-
- BufferedWriter bufout = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
-
- String line = null;
- while((line=bufrin.readLine())!=null)
- {
- bufout.write(line.toUpperCase());
- bufout.newLine();
- bufout.flush();
- }
- s.close();
- ss.close();
- }
- }
复制代码 [/code] |