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("关闭时出现异常";}
}
}
}
raksmart作为一家老牌美国机房总是被很多人问到raksmart香港服务器怎么样、raksmart好不好?其实,这也好理解。香港服务器离大陆最近、理论上是不需要备案的服务器里面速度最快的,被过多关注也就在情理之中了。本着为大家趟雷就是本站的光荣这一理念,拿了一台raksmart的香港独立服务器,简单做个测评,分享下实测的数据,仅供参考!官方网站:https://www.raksmart.com...
SugarHosts 糖果主机商也算是比较老牌的主机商,从2009年开始推出虚拟主机以来,目前当然还是以虚拟主机为主,也有新增云服务器和独立服务器。早年很多网友也比较争议他们家是不是国人商家,其实这些不是特别重要,我们很多国人商家或者国外商家主要还是看重的是品质和服务。一晃十二年过去,有看到SugarHosts糖果主机商12周年的促销活动。如果我们有需要香港、美国、德国虚拟主机的可以选择,他们家的...
Hostodo 商家是比较小众的国外VPS主机商,这不看到商家有推送促销优惠在美国西岸的斯波坎机房还有少部分库存准备通过低价格促销,年付低至12美元Linux VPS主机,且如果是1GB内存方案的可以享受六六折优惠,均是采用KVM架构,且可以支付宝付款。第一、商家优惠码优惠码:spokanessd 1GB+内存方案才可以用到优惠码,其他都是固定的优惠低至年12美元。第二、商家促销这里,我们可以看到...