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("关闭时出现异常";}
}
}
}
欧路云(oulucloud) 商家在前面的文章中也有陆续介绍过几次,这不今天有看到商家新增加美国Cera线路的VPS主机,而且有提供全场八折优惠。按照最低套餐最低配置的折扣,月付VPS主机低至22元,还是比较便宜的。不过我们需要注意的是,欧路云是一家2021年新成立的国人主机商,据说是由深圳和香港的几名大佬创建。如果我们有介意新商家的话,选择的时候谨慎且月付即可,注意数据备份。商家目前主营高防VP...
Fiberia.io是个新站,跟ViridWeb.com同一家公司的,主要提供基于KVM架构的VPS主机,数据中心在荷兰Dronten。商家的主机价格不算贵,比如4GB内存套餐每月2.9美元起,采用SSD硬盘,1Gbps网络端口,提供IPv4+IPv6,支持PayPal付款,有7天退款承诺,感兴趣的可以试一试,年付有优惠但建议月付为宜。下面列出几款主机配置信息。CPU:1core内存:4GB硬盘:...
georgedatacenter这次其实是两个促销,一是促销一款特价洛杉矶E3-1220 V5独服,性价比其实最高;另外还促销三款特价vps,georgedatacenter是一家成立于2019年的美国VPS商家,主营美国洛杉矶、芝加哥、达拉斯、新泽西、西雅图机房的VPS、邮件服务器和托管独立服务器业务。georgedatacenter的VPS采用KVM和VMware虚拟化,可以选择windows...