本帖最后由 唐志海 于 2014-1-18 19:39 编辑
- import java.io.*;
- import java.net.*;
- /*客户端*/
- class TcpDemo
- {
- public static void main(String[] args) throws UnknownHostException, IOException
- {
-
- Socket s=new Socket("110.85.116.140",10008);
- //获取键盘录入的数据
- BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
- //得到发数据的流
- BufferedWriter bwout=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
- //接收服务端发来的数据
- BufferedReader bfin=new BufferedReader(new InputStreamReader(s.getInputStream()));
- String line=null;
- while((line=bf.readLine())!=null)
- {
- if(line.equals("over"))
- break;
- bwout.write(line);
- bwout.newLine();
- bwout.flush();
- String ss=bfin.readLine();
- System.out.println("server....."+ss);
- }
- bf.close();
- s.close();
-
- }
- }
- class Server
- {
- public static void main(String[] args) throws IOException
- {
- ServerSocket ss=new ServerSocket(10008);
- Socket s=ss.accept();
- String ip=s.getInetAddress().getHostAddress();
- System.out.println(ip);
- BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
- BufferedWriter bfout=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
- String line=null;
- while((line=br.readLine())!=null)
- {
- System.out.print("shoudao??");
- bfout.write(line.toUpperCase());
- bfout.newLine();
- bfout.flush();
- }
- s.close();
-
- }
- }
复制代码 为什么运行客户端的时候会报错。。 |
|