服务端- package com.cn.test;
- import java.net.*;
- import java.io.*;
- public class TCPUpServer {
- public static void main(String[] args) throws Exception{
- ServerSocket ss=new ServerSocket(5245);
- Socket s=ss.accept();
- BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintWriter pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream()),true);
- // InputStream is=s.getInputStream();
- // int len=0;
- // byte buf[] =new byte[1024];
- String line=null;
- while((line=br.readLine())!=null){
- String up=line.toUpperCase();
- pw.println(up);
- }
- s.close();
- ss.close();
-
-
-
- }
- }
复制代码
客户端
- package com.cn.test;
- import java.io.*;
- import java.net.*;
- public class TCPUpClient {
- public static void main(String[] args) throws Exception {
- Socket s=new Socket(InetAddress.getByName("192.168.1.4"),5245);
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- BufferedReader brAfter=new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintWriter pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream()),true);
- String line=null;
- while((line=br.readLine())!=null){
- if("886".equals(line)){
- break;
- }
- pw.println(line);
- String upReader=brAfter.readLine();
- System.out.println(upReader);
- }//发送完毕
- s.close();
- //
-
- }
- }
复制代码
|
|