- import java.io.*;
- import java.net.*;
- class TransClient
- {
- public static void main(String[] args) throws Exception
- {
- Socket s = new Socket("192.168.1.254",10005);
- //定义读取键盘数据的流对象。
- BufferedReader bufr =
- new BufferedReader(new InputStreamReader(System.in));
- //定义目的,将数据写入到socket输出流。发给服务端。
-
- PrintWriter out = new PrintWriter(s.getOutputStream(),true);
- //定义一个socket读取流,读取服务端返回的大写信息。
- BufferedReader bufIn =
- new BufferedReader(new InputStreamReader(s.getInputStream()));
- String line = null;
-
- while((line=bufr.readLine())!=null)
- {
- if("over".equals(line))
- break;
-
- out.println(line);
- String str =bufIn.readLine();
- System.out.println("server:"+str);
-
- }
- bufr.close();
- s.close();
- }
- }
- /*
- 服务端:
- 源:socket读取流。
- 目的:socket输出流。
- */
- class TransServer
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss = new ServerSocket(10005);
- Socket s = ss.accept();
- String ip = s.getInetAddress().getHostAddress();
- System.out.println(ip+"....connected");
- //读取socket读取流中的数据。
- BufferedReader bufIn =
- new BufferedReader(new InputStreamReader(s.getInputStream()));
- //目的。socket输出流。将大写数据写入到socket输出流,并发送给客户端。
-
- PrintWriter out = new PrintWriter(s.getOutputStream(),true);
- String line = null;
- while((line=bufIn.readLine())!=null)
- {
- System.out.println(line);
- out.println(line.toUpperCase());
- }
- s.close();
- ss.close();
- }
- }
复制代码
怎么没反应? |
|