資源簡介
卡耐基 SSD8答案(全 exam+qiuz+excerise)

代碼片段和文件信息
package?exercise2;
//200532580182?pengxu
import?java.io.*;
import?java.net.*;
public?class?ModifiedClient?{
??//the?client?socket?used?to?connect?to?server
private?Socket?clientSocket;
//read?the?user?input?from?keyboard
BufferedReader?inFromKeyBoard;
//get?the?information?response?by?the?server
BufferedReader?inFromServer;
//send?the?user?input?to?the?sever?
DataOutputStream?outToServer;
public?ModifiedClient(){
this.clientSocket=null;
}
//connect?to?the?server?
public?void?connect(String?hostint?port){
try{
this.clientSocket=new?Socket(hostport);
//read?from?keyboard
this.inFromKeyBoard=new?BufferedReader
???????????????????(new?InputStreamReader(System.in));
//read?from?the?client?socket
this.inFromServer=new?BufferedReader
???????????????????(new?InputStreamReader(clientSocket.getInputStream()));
//output?to?server?socket
this.outToServer=new?DataOutputStream
???????????????????(clientSocket.getOutputStream()?);
}catch(Exception?e){
e.printStackTrace();
}
}
public?void?close(){
try{
//close?the?socket
this.clientSocket.close();
}catch(Exception?e){
e.printStackTrace();
}
}
public?static?void?main(String?[]?args)?throws?Exception{
if(args.length!=1){
System.out.println(“Usage:?Client?“);
System.exit(0);
}
else{
try{
double?sendBytes;
double?recieveBytes;
final?int?port=80;
ModifiedClient?client=new?ModifiedClient();
//connnect?to?the?user?defined?host(argv[0])?use?port?80
client.connect(args[0]?port);
System.out.println(args[0]?+?“?is?listening?to?you?request:“);
//read?the?user?input?from?keyboard?assign?to?s
String?s=client.inFromKeyBoard.readLine();
s+=“\r\n“?+?“\r\n“;
//send?s?to?server
client.outToServer.writeBytes(s);
//get??the?sendBytes
sendBytes=s.length();
//get?the?response?header?and?show?to?the?user
String?file=““;
String?temp=file;
int?i=0;
boolean?flag=true;
for(int?j=0;?flag&&((j=client.inFromServer.read())!=-1);){
switch(j)
????????????{
????????????case?13:?//?‘\r‘
????????????????break;
????????????case?10:?//?‘\n‘
????????????????if(j?==?i)
????????????????{
????????????????????flag?=?false;
????????????????}?else
????????????????{
????????????????????i?=?j;
????????????????????file+=“\r\n“;
????????????????}
????????????????break;
????????????default:
????????????????i?=?j;
????????????file+=(char)j;
????????????????break;
????????????}
}
System.out.println(“Header:“);
System.out.println(““);
System.out.println(file);
//get?the?recieveBytes
recieveBytes=file.length();
file=““;
temp=client.inFromServer.readLine();
//get?the?response?context
while(temp!=null){
file=file?+?“\r\n“+temp;
temp=client.inFromServer.readLine();
}
??????????//?save?the?response?text?to?a?file
System.ou
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3476??2010-03-21?23:27??Modified---Client.java
?????文件??????14577??2010-03-21?23:25??ssd8+===+exam3.rar
?????文件???????9585??2010-03-21?23:28??ssd8+EXAM1+選擇題---+Multiple-Choice.txt
?????文件??????10388??2010-03-21?23:24??ssd8+---exercise1.rar
?????文件?????139016??2010-03-21?23:16??SSD8-==-=-Exam3.rar
?????文件??????10194??2010-03-21?23:18??SSD8=-=-Exercise1.rar
?????文件???????4697??2010-03-21?23:30??ssd8---E1.rar
?????文件??????21455??2010-03-21?23:25??ssd8---exam3.rar
?????文件??????21726??2010-03-21?23:23??ssd8----exam3.rar
?????文件???????7603??2010-03-21?23:21??ssd8----exam11.txt
?????文件???????3563??2010-03-21?23:20??ssd8--exercise4.rar
?????文件???????8670??2010-03-21?23:16??ssd8---exercise1.rar
?????文件???????4169??2010-03-21?23:17??ssd8---exercise2.rar
?????文件???????4447??2010-03-21?23:19??ssd8----exercise5.rar
?????文件???????8691??2010-03-21?23:26??WebProxyServer0000.java
?????文件?????389895??2010-04-11?19:29??choice.txt
-----------?---------??----------?-----??----
???????????????662152????????????????????16
評論
共有 條評論