package_ho mework 11;importjava.io.*;importjava.net.*;public class C lient {public final static int Default_Port=6666;//定义异常信息显示public final static void message(String s{
System.out.println("使用方法:Java C lient"+s;Sys te m.e xit(0;
}public static void main(String args[]{int port=Default_Port;
S ocket s=null;if((ar gs.le ngth!=1&&(ar gs.le ngth!=2message(;if(args.length==1 {port=Default_Port;
}else{try{
port=Inte ger.parseInt(args[1];
}catch(NumberFormatExcep tio n e{message(;
}
}try{
//产生一个Socket ,通过指定的端口与主机通信s=new Socket(args[0],port;
BufferedReader sin=new BufferedReader(new InputStreamReader(s.getInputStream(;
PrintStream sout=new PrintStream(s.getOutputStream(;
BufferedReader in=new BufferedReader(new InputS treamReader(System.in;
//返回连接地址
System.out.println("已连接到:"+s.getInetAddress(+":"+s.getPort(;S tring line;for(; ;{
Sys te m.o ut.pr int(">";
System.out.flush(;
//读信息
line=in.readLine(;if(line==null break;
//把信息发给服务器sout.pr intln(line;line=s in.readLine(;if(line==null{
S ys te m.o ut.pr int ln("服务器已关闭";b re ak;}
Sys te m.o ut.println(line;
}
}catch(IOException e 1{
System.err.println(e1;
}finally{try{if(s !=null s.c lose(;
}catch(IOException e2{
Sys te m.o ut.pr int ln("关闭时出现异常"; }}
}
}
package_ho mework 11;importjava.io.*;importjava.net.*;public class Server extends Thread{public final static int Default_Port=6666;protected int port;protected ServerSocket listen_socket;
//异常处理public static void fail(Exception e,String msg{System.err.println(ms g+":"+e;
Sys te m.e xit(0;
}
//监听客户端的连接请求pub lic Server(int port {if(port==0 port=Default_Port;this.port=port;try{listen_socket=new ServerSocket(port;
}catch(IOException e{
fail(e,"Exception occur in server socket"; }
System.out.println("Server: listening on port"+port; start(;
}
//接收客户端发出的连接请求并产生对象与之对应pub lic vo id run( {try{while(true{
Socket client_socket=listen_socket.accept(;
LinkedList linked=new LinkedList(client_socket;
}
}catch(IOException e{fail(e,"Exception while listening for links";
}
}public static void main(String args[]{int port=0;if(args.length==1 {try{port=Inte ger.parseInt(args[0];
}catch(NumberFormatExcep tio n e{
port=0;
System.out.println("port numb er not input";}
}new Server(port;
}
}package_ho mework 11;importjava.io.*;importjava.net.*;public class LinkedList extends Thread{protected Socket client;protected BufferedReader in;protected PrintStream out;
//启动线程public LinkedList(Socket client_socket {c lient=c lient_socket;try{in=new BufferedReader(
new InputStreamReader(client.getInputStream(;out=new PrintStream(c lie nt.ge tOutp utS tream(;
} catch(IOException e{try{c lient.c lose(;
}catch(IOException e2{
Sys te m.o ut.pr int ln("无法关闭";
}
Sys te m.e rr.println("在S ock et上建立流时出现问题:"+e;re turn;}s tar t(;
}
//服务器读取信息后反转文本并发送pub lic vo id run({
String line="";
StringBuffer revline;int len;try{for(; ;{
line=in.readLine(;if(line==nullbr eak;len=line.length(;revline=new StringBuffer(len;for(int i=len-1;i>=0;i--revline.insert(len-1-i,line.charAt(i;out.p rintln(re vline;
}
}catch(IOException e{
Sys te m.o ut.pr int ln("读取时出现异常";}finally{try{c lient.c lose(;
}catch(IOException e2{
Sys te m.o ut.pr int("关闭时出现异常";}
}
}
}
atcloud怎么样?atcloud刚刚发布了最新的8折优惠码,该商家主要提供常规cloud(VPS)和storage(大硬盘存储)系列VPS,其数据中心分布在美国(俄勒冈、弗吉尼亚)、加拿大、英国、法国、德国、新加坡,所有VPS默认提供480Gbps的超高DDoS防御。Atcloud高防VPS。atcloud.net,2020年成立,主要提供基于KVM虚拟架构的VPS、只能DNS解析、域名、SS...
我们一般的站长或者企业服务器配置WEB环境会用到免费版本的宝塔面板。但是如果我们需要较多的付费插件扩展,或者是有需要企业功能应用的,短期来说我们可能选择按件按月付费的比较好,但是如果我们长期使用的话,有些网友认为选择宝塔面板企业版或者专业版是比较划算的。这样在年中大促618的时候,我们也可以看到宝塔面板也有发布促销活动。企业版年付899元,专业版永久授权1888元起步。对于有需要的网友来说,还是值...
LightNode是一家位于香港的VPS服务商.提供基于KVM虚拟化技术的VPS.在提供全球常见节点的同时,还具备东南亚地区、中国香港等边缘节点.满足开发者建站,游戏应用,外贸电商等应用场景的需求。新用户注册充值就送,最高可获得20美元的奖励金!成为LightNode的注册用户后,还可以获得属于自己的邀请链接。通过你的邀请链接带来的注册用户,你将直接获得该用户的消费的10%返佣,永久有效!平台目前...