黑马程序员技术交流社区
标题:
TCP服务端转成大写字母
[打印本页]
作者:
sven556677
时间:
2015-8-21 17:08
标题:
TCP服务端转成大写字母
服务端
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();
//
}
}
复制代码
作者:
风华正茂
时间:
2015-8-21 18:01
谢谢楼主分享
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2