2.2阅读“网络编程参考资料-传输层.pdf”中11.3 部分,输入11.
3.4 部
分“TCP服务器程序”(Tcp_Server.java)以及11.3.5客户端程序的源代码(Tcp_Client.java)并在机器上编译运行,客户端测试命令为“java Tcp_Client 自己的IP地址8001”。
【程序源代码】
TCP:
import http://www.doczj.com/doc/39bfdffbf90f76c661371a77.html.*;
import java.io.*;
class Servicer implements h2{
Socket s;
public Servicer(Socket s){
this.s = s;
}
public void run(){
try{
InputStream ips = s.getInputStream();
OutputStream ops = s.getOutputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(ips));
DataOutputStream dos = new DataOutputStream(ops);
while(true){
String strWord = br.readLine();
//System.out.println(strWord + ":" + strWord.length());
if(strWord.equalsIgnoreCase("quit"))
break;
String strEcho = (new StringBuffer(strWord).reverse()).toString();
//dos.writeBytes(strWord + "---->" + strEcho + "\r\n");
dos.writeBytes(strWord + "---->" + strEcho + System.getProperty("line.separator"));
}
br.close();
dos.close();
s.close();
}catch(Exception e){