- package cn.itcast.net.TPC;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.Socket;
- import java.net.UnknownHostException;
- public class TransClient {
- public static void main(String[] args) throws UnknownHostException, IOException {
-
- Socket s=new Socket("127.0.0.1",10014);
-
- BufferedReader bufr=new BufferedReader(new InputStreamReader(System.in));
-
- BufferedWriter bufw=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
- //PrintWriter out =new PrintWriter(s.getOutputStream(),true);
-
-
- BufferedReader bufrin=new BufferedReader(new InputStreamReader(s.getInputStream()));
-
- String line=null;
- while ((line=bufr.readLine())!=null) {
- if("over".equals(line))
- break;
-
- bufw.write(line);
-
- String str=bufrin.readLine();
-
- System.out.println("转换后"+str);
- }
- s.close();
- }
- }
复制代码- package cn.itcast.net.TPC;
- 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 TransServer {
- public static void main(String[] args) throws IOException {
- ServerSocket ss=new ServerSocket(10014);
-
- Socket s=ss.accept();
-
- System.out.println(s.getInetAddress().getHostName());
-
- BufferedReader bufIn=new BufferedReader(new InputStreamReader(s.getInputStream()));
-
- PrintWriter out=new PrintWriter(s.getOutputStream(),true);
-
- String line=null;
-
- while ((line=bufIn.readLine())!=null) {
- out.println(line.toUpperCase());
- }
- s.close();
- ss.close();
- }
- }
复制代码 做了一个,TCP协议的服务器客户端,服务器只负责把输入的字母转换成大写,我这样写不能翻译,错在了哪?
|