题目内容

阅读以下说明和Java程序代码,将应填入(n)处的字句写在对应栏内。
SMTP是发送E-mail的协议,常用以下5条命令发送E-mail:
HELO,与SMTP服务器握手,传送本机域名;
MAILFROM:,传送发信者的信箱名称;
RCPTTO:,传送接收者的信箱名称;
DATA,发送邮件数据(包括信头和信体);
QUIT,退出与SMTP服务器的连接。
2.试题中直接利用的类及方法如下:
(1)类ServerSocket(int port)实现TCP服务器接口(socket),它提供两种构造函数,用它们来指定服务器插口所用的端口,并监听到达的连接请求。类中的主要方法有:
accept():启动服务器插口监听并等待,直到建立连接为止,一旦建立连接就返回Socket类的一个对象。
getInetAddress():返回插口所连接的主机地址。
getLocaIPort():返回在服务器插口上建立了连接的端口。
close():关闭服务器插口。
(2)类InetAddress包装了Internet地址。类中的主要方法有:
getLocaIHost():返回一个代表本机Internet地址的InetAddress对象。
getaddress():获得数字表示的IP地址。
getHostName():获得域名。
(3)类Socket实现基于连接的客户插口。类中的主要方法有getInetAddress():返回一个与插口连接的客户机的Internet地址,其类型为InetAd-dress。getlnputStream():用来访问与插口相关的输入流。getOutputStream():用来访问与插口机关的输出琉。close():关闭插口。
(4)readLine()是输入流类的一个方法,用于服务器或客户从对方读入一行输入流信息。
(5)用户白定义类NVTInputStream(InputStream inStream, OutputStream outStream)实现了网络虚拟终端输入接口。
(6)用户自定义类NVTOutputStream(OutputStream outStream)实现了网络虚拟终端输接口。
3.下面是用Java语言实现的一个简单SMTP服务器程序的部分代码。
[程序代码]
import java.net. *:
import java.io. *;
import jdg. yan. NVTlnputStream; //用户自定义类包
import jdg. yan. NVTOutputStream; //用户自定义类包
public class SMTPServer App
{
public static void main(String args[])
{
SMTPServer server=new SMTPServer();
server. run();
}
}
class SMTPServer
{
static final int HELO=1;
static final int MAIL=2;
static final int RCPT=3;
static final int DATA=4;
static final int END_DATA=5;
static final int OUIT=6;
static final int FINISHED=9;
NVTOutputStream out;
NVTInputStream in;
String hostName;
public SMTPServer()
{
super();
}
public void run(){
try{
ServerSOcket server=(1);//在1145号端口建立下CP服务器插口
int localPort=server. getLocalPort();//监听连接端口
hostNama=(2);//获取本地主机域名
SVstem. out. prfntln("listening on port"+locaIPort+".");
boolean finished=false;
do {
Socket client=(3);//监听等待,直到建立连接,返回对象client
Stnng destName=(4);//获得所连接的客户主机IP地址的域名
int destPort=client. getPort();//所连接的客户主机端口号
System. out pnntln("Accepted connection to"+destNama+"on port"+destPort+"."
//控制台显示连接
out=new NVT0utputStream(client. get OutputStream());
In=new NVTInputStream((5));//建立与连接关联的输入流
(6);//接收邮件
(7);//关闭连接对象
}while(! finished);
}catch(UnknownHostException ex){
SVstem.out.printtn("UnknownHostException occurred.");//出错处理
}cath(lOException ex){
System. out. println("lOException occurred.");
}
}
vold getMail(){ //实现SMTP的子集,从客户接收邮件
out. println("Server220"+hostName+"Ready!");
int state=HELO; //设置状态为HELO,state保存与客户通信的状态
do{ //接收并处理从邮件客户接收到的命令
String line="";
out. println("Server 250 HELO, OK!");
try{
line=(8);//从虚拟终端读取一行
if(line==null)state=FINISHED;
}catch(IOException ex){
System. out. prmntln("Server IOExceptlon occurred.");
System.exit(1);
}
switch(state){
case HELO:
if((9))//若该行信息为传送本机域名
{
out. println("Server 250 Hello");
System. out. println(line);
state=MAIL;
}else{
out. println("Server 500 ERROR");
System. out. println("Server"+line);
}
state=FINISHED;
break'
case MAIL: //省略代码
case RCPT:

查看答案
更多问题

阅读以下说明、Java源程序和运行测试部分,将应填入(n)处的解答写在对应栏中。
1. HTTP 协议
HTTP请 求消息示例
GET/index, htmIHTTP/1.1
Accept: image/gif, image/jpeg, */*
Accept-Language: zh-ch
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE6.0; Windows NT5.1)
Host: IocaIhost: 8080
Connection: Keep-Alive
HTTP/1.1 200 OK
Servert: Microsoft-IIS/4.0
Date: Mon, 3 Jan 1998 13:13:33 GMT
Content-Type: text/html
Last-Modified: Mon, 11 Jan 1998 13:23:42 GMT
Contelit-Length: 112
< html >

2.相关类及主要成员函数
ServerSocket类:
服务器端套接字,它监听固定端口,以接收来自客户端的连接请求,一旦建立连接就返回一个Socket类型的对象。类中的主要成员函数见表1。
基于连接的套接字。类中的主要成员函数见表2。
[Java源程序;一个简单的web服务器]
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*WebScrvc. java */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
packageobjclass;
importjaVa. net. *;
importjaVa. io. *;
public class WebServer{
//web服务器侦听的端口号
public static final int PORT=8080;
//WEB-ROOT变量存放web服务器工作目录,该目录存放HTML、GIF图片等静态文件资源
public static final String WEB-ROOT=
Systern. getProperty("user.dir")+File. separator+"webmot";
//SHUTDOWN_COMMAND变量保存关闭服务器的命令
private static final string SHUTDOWN_COMMAND="/shutdown";
//是否收到关闭服务器命令的标志
private boolean Shutdown=false;
public static void main(Sting[]args){
WebServerserver; newWebserver();
Server.await();
}
public void await(){
ServerSocke serverSocke=null;
try{
//创建侦听端口号为PORT的ServerSocket类型的对象
ServerSocket=new(1);
System. out. println("WebServerStarted!");
!
catch(IOException e){
e.printStackTrace();
System.exit (1);
}
//循环等待客户端连接
While(!Shutdown){
Socket socket=null;
InputStream input=null;
OutputStream output=null;
try{
//创建来自客户端的连接套接宇
Socket=(2);
//创建输入流
input=socket. (3);
//创建输出流
Output=socket. (4);
//创建request对象
Request request=new Request(input);
//解析客户端HTTP请求
request, parse();
//创建Response 对象
Response response=new (5);
//将 request 对象传递给 response 对象
response. setRequest(request);
//给客户端发送所请求的静态资源
response. (6);
//关闭连接套接字
(7);
//判断当前HTTP 请求中的URI是否是关闭服务器命令
shutdown-request. getUri(). equals(SHUTDOWN_COMMAND);
Catch (Exception e) {
e. (8);
continue;
}
}
}
}
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/ * Request. java * /
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
package objclass;
import java.io.InputStream;
import java.io.IOEexception;
public Class Request{
private InputStream input;
private String uri;

Part A
Letter-Writing (100 words)
Letter of Invitation

阅读下面段落,按要求回答问题。
这一天本在意料之中,可是我怎能相信这是事实呢!他躺在那里,但他已经不是他了,已经不是我那正当盛年的弟弟,他再也不会回答我们的呼唤,再不会劝阻我们的哭泣。你到哪里去了,小弟!自一九七四年沅君姑母逝世起,我家屡遭丧事,而这一次小弟的远去最是违反常规,令人难以接受!我还不得不把这消息告诉当时也在住院的老父,因为我无法回答他每天的第一句问话:“今天小弟怎么样?”我必须告诉他,这是我的责任。再没有弟弟可以依靠了,再不能指望他来分担我的责任了。父亲为他写了挽联:“是好党员,是好干部,壮志未酬,洒泪岂只为家痛;能娴科技,能娴艺文,全才罕遇,招魂也难再归来!”我那唯一的弟弟,永远地离去了。
作者在这一段文字中,是通过什么方式来抒情的?
作者为什么要说“这一次小弟的远去最是违反常规,令人难以接受”?
父亲为小弟写挽联,这是什么描写?有什么表达作用?
请帮忙给出每个问题的正确答案和分析,谢谢!

When you are in the business of sending spacecraft to other planets, it is probably wise to do everything you can m keep your space-probes sterile (无菌的). NASA, America's space agency, certainly does so. After all, you would not want hugs from one planet to contaminate another where they might possibly thrive.
But according to Curt Mileikowsky, of the Royal Institute of Technology in Stockholm, this may already have happened naturally billions of years ago when the solar sys- tem was young. For Dr Mileikowsky has taken a century-old idea called panspermia (有生源说), and shown that it is plausible.
57. Panspermia is the theory that life does not start independently on each planet that has it (assuming that other planets do). Rather, it hops from place to place, "infecting" new worlds as it goes. Supported by experts in biology, geology and celestial mechanics, Dr Mileikowsky argued to the American Astronomical Society meeting in Atlanta that this is not as outlandish as it sounds.
58. Bungling (笨手笨脚) space organizations apart, the only mode of travel open to microbes seems to be meteorites (流星). Most of these are small bits of junk from the asteroid (小行星) belt that have gone off course. But some are rocks that have been flung into space from the surfaces of planets as a result of those planets having been struck by even larger bits of rock--decent-sized asteroids or comets.
59. If there is life on such a planet, microscopic forms of it will probably live deep in- side rocks, as they do on earth. The acceleration of lift-off would not kill something that size.
60. If a rock is large enough, the heat generated as it is thrown clear will be negligible except at its surface--where, ii anything, melting may even produce an airtight skin to protect any microbes deeper down from the unpleasant vacuum of space.
(56)

答案查题题库