问题 问答题


阅读以下说明和Java程序代码,将应填入 (n) 处的字句写在对应栏内。
1.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: //省略代码
case DATA:
if( (10) )//若该行信息为发送邮件数据
{
out. println("354 mail input; end with.");
System. out. println(line);
state=END_DATA;
}else{
out. println("500 ERROR");
System. out. println(line);
}
break;
case END_DATA;//代码省略
case QUIT://代码省略
}
}while(state!=FtNISHED);
}
//判断客户收到的命令是否与指定的命令字符串相匹配
boolean commandls(String s, String line){
int n=s. length( );
if(s.equalslgnoreCase(line. substring(0.n)))return true;
return false;
}
}

答案

参考答案:

解析:(7)client. close( ) 关闭连接对象。

多项选择题
阅读理解

Online Degrees

Today, you can earn a degree from a major university without ever having sat in one of their classrooms. Many colleges and universities are offering online courses and degree programs now.

Online Learning Programs

With a computer and an Internet connection, you can earn a degree from home, work, or anywhere else for that matter. Online degree programs follow much the same routines as traditional learning, with a few twists. There are lectures, but they won't be in person. There are assignments (作业) , but you won't hand them to your instructor. In most situations, you are free to "go to class" when it fits your"schedule. If you get a phone call during class, you don't have to miss anything. If you get sick, you don't have to ask for someone's notes, and you just visit the lecture later.

You'll communicate with your instructor by e-mail, chat room and instant messaging. Your  classroom will live in a special software program. Contrary to popular belief, you will have close  contact with other students and the instructor.

Evaluating the Program

There are a lot of questions to ask before you make your selection, such as:

How do students interact with each other?

★Online programs can use chat rooms, instant messaging, teleconferencing, and video conferencing to communicate. The key is to find a program that has this interaction built into it and even requires it.

★What kind of reputation does the school have?

It may seem simple-a good school will have a good online program. This reputation,however, may not be as straightforward as you think. It's not uncommon for a great school to have a weak program or two. So you'd better look at the overall quality of the school and make a judgment.

The Employers' View

As more and more employees get online degrees and use them in the workforce(职场) ,  hiring managers will begin to feel more secure about the quality of education these people have.

小题1:In which way is online education special?

A.If you get sick, you'll miss the lecture.

B.There are lectures, but you don't need to meet the lecturers.

C.If you get a phone call during class, you will miss something.

D.There are assignments, and you must hand them to your instructor.小题2:What is the most important part of online communication?

A.To use e-mails.

B.To look for a program with interaction.

C.To use chat rooms and instant messaging.

D.To use teleconferencing and video conferencing.小题3:For whom is the passage probably written?

A.College students.

B.Hiring managers.

C.Adult students.

D.High school students.