分布式系統(tǒng)實驗報告_第1頁
分布式系統(tǒng)實驗報告_第2頁
分布式系統(tǒng)實驗報告_第3頁
分布式系統(tǒng)實驗報告_第4頁
分布式系統(tǒng)實驗報告_第5頁
已閱讀5頁,還剩34頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

中南大學(xué)分布式系統(tǒng)實驗報告目錄(我選做4題,按住ctrl點擊目錄條可直達,wps下有效)TOC\o"1-2"\h\u32494實驗一數(shù)據(jù)包socket應(yīng)用 315207一、實驗?zāi)康?315042二、預(yù)習(xí)與實驗要求 311917三、實驗環(huán)境 33332四、實驗原理 421958五、實驗內(nèi)容 523037六、實驗報告 520752七、思考題 717190實驗二流式socket應(yīng)用 832680一、實驗?zāi)康?81986二、預(yù)習(xí)與實驗要求 85310三、實驗環(huán)境 89051四、實驗原理 89861五、實驗內(nèi)容 824824六、實驗報告 913051七、思考題 124430實驗三客戶/服務(wù)器應(yīng)用開發(fā) 1212268一、實驗?zāi)康?1217214二、預(yù)習(xí)與實驗要求 1210225三、實驗環(huán)境 126482四、實驗原理 1213432五、實驗內(nèi)容 1327674六、實驗報告 1325892實驗九虛擬機的使用與Linux系統(tǒng)的安裝 3010403一、實驗?zāi)康?3026367二、實驗內(nèi)容和步驟 304947三、實驗結(jié)果 32實驗一數(shù)據(jù)包socket應(yīng)用一、實驗?zāi)康?.理解數(shù)據(jù)包socket的應(yīng)用2.實現(xiàn)數(shù)據(jù)包socket通信3.了解Java并行編程的基本方法二、預(yù)習(xí)與實驗要求1.預(yù)習(xí)實驗指導(dǎo)書及教材的有關(guān)內(nèi)容,了解數(shù)據(jù)包socket的通信原理;2.熟悉一種javaIDE和程序開發(fā)過程;3.了解下列JavaAPI:Thread、Runnable;4.盡可能獨立思考并完成實驗。三、實驗環(huán)境a)獨立計算機或計算機網(wǎng)絡(luò);b)Windows操作系統(tǒng)。c)Jdk工具包d)JCreatororothers四、實驗原理1.分布式計算的核心是進程通信。操作系統(tǒng)、網(wǎng)卡驅(qū)動程序等應(yīng)用從不同抽象層面提供了對進程通信的支持,例如Winsock、.*。SocketAPI是一種作為IPC提供對系統(tǒng)低層抽象的機制。盡管應(yīng)用人員很少需要在該層編寫代碼,但理解socketAPI非常重要,因為:1,高層設(shè)施是構(gòu)建于socketAPI之上的,即他們是利用socketAPI提供的操作來實現(xiàn);2,對于以響應(yīng)時間要求較高或運行于有限資源平臺上的應(yīng)用來說,socketAPI可能是最適合的。在Internet網(wǎng)絡(luò)協(xié)議體系結(jié)構(gòu)中,傳輸層上有UDP和TCP兩種主要協(xié)議,UDP允許在傳送層使用無連接通信傳送,被傳輸報文稱為數(shù)據(jù)包。(是否存在面向連接的數(shù)據(jù)包socket)因此數(shù)據(jù)包socket是基于UDP的不可靠IPC。Java為數(shù)據(jù)包socketAPI提供兩個類:(1)針對socket的datagramSocket類(2)針對數(shù)據(jù)包交換的datagramPacket類希望使用該API發(fā)送和接收數(shù)據(jù)的進程須實例化一個datagramSocket對象,每個socekt被綁定到該進程所在及其的某個UDP端口上。為了向其他進程發(fā)送數(shù)據(jù)包,進程必須創(chuàng)建一個代表數(shù)據(jù)包本身的對象。該對象通過實例化一個datagramsocket對象創(chuàng)建。在接收者進程中,datagramPacket對象也必須被實例化并綁定到一個本地端口上,該端口必須與發(fā)送者數(shù)據(jù)包的定義一致。接收進程創(chuàng)建一個指向字節(jié)數(shù)組的DatagramPacket,并調(diào)用datagramSocket對象的receive方法,將DatagramPacket對象指針作為參數(shù)定義。2.并行編程(以Java為例1)一個線程是比進程更小的執(zhí)行粒度。Java虛擬機允許應(yīng)用程序有多個執(zhí)行線程同時運行。有兩種方法來創(chuàng)建一個新線程的執(zhí)行。一個是聲明一個類是一個線程的子類。這個子類應(yīng)重寫Thread類的run方法。一個子類的實例可以被分配和啟動。另一種方法創(chuàng)建一個線程,并同時聲明一個類實現(xiàn)了Runnable接口(這個類要實現(xiàn)run方法)。一個類的實例可以被分配并作為參數(shù)傳遞給創(chuàng)建的線程,并啟動線程。例如:創(chuàng)建一個類是Thread的子類:classSomeThreadextendsThread{SomeThread(){}publicvoidrun(){...}}SomeThreadp=newSomeThread();();創(chuàng)建一個實現(xiàn)Runnable接口的類并傳遞給線程:classSomeRunimplementsRunnable{SomeRun(){}publicvoidrun(){...}}SomeRunp=newSomeRun(143);newThread(p).start();當(dāng)一個實現(xiàn)Runnable接口的類被執(zhí)行時,可以沒有子類。實例化一個Thread實例,并通過自身作為目標(biāo)線程。在大多數(shù)情況下,如果你只打算重寫的run()方法,并沒有其它的線程方法,應(yīng)使用Runnable接口。因為類不應(yīng)該被繼承,除非程序員有意修改或增強類的基本行為。五、實驗內(nèi)容1.構(gòu)建客戶端程序(1)構(gòu)建datagramSocket對象實例(2)構(gòu)建DatagramPacket對象實例,并包含接收者主機地址、接收端口號等信息(3)調(diào)用datagramSocket對象實例的send方法,將DatagramPacket對象實例作為參數(shù)發(fā)送。2.構(gòu)建服務(wù)器端程序(1)構(gòu)建datagramSocket對象實例,指定接收的端口號。(2)構(gòu)建DatagramPacket對象實例,用于重組接收到的消息。(3)調(diào)用datagramSocket對象實例大家receive方法,進行消息接收,并將DatagramPacket對象實例作為參數(shù)。六、實驗報告1.客戶端和服務(wù)器端程序的偽代碼;客戶端:importclassClient{publicstaticvoidmain(String[]args)throwsIOException{ etBytes();如何避免數(shù)據(jù)包丟失而造成的無限等待問題答:我認(rèn)為可在發(fā)包時設(shè)定一個定時器,若發(fā)出去的包在一定時間內(nèi)沒有收到答應(yīng),則再發(fā)一次。為了避免接受者接到重復(fù)的包,可以給數(shù)據(jù)包加個序號,接受者收包時查看序號即可。如何實現(xiàn)全雙工的數(shù)據(jù)包通信答:利用端口套接字之間的通信功能。實驗二流式socket應(yīng)用一、實驗?zāi)康?.理解流式socket的原理2.實現(xiàn)流式socket通信二、預(yù)習(xí)與實驗要求1.預(yù)習(xí)實驗指導(dǎo)書及教材的有關(guān)內(nèi)容,了解流式socket的通信原理;2.熟悉java環(huán)境和程序開發(fā)過程;3.盡可能獨立思考并完成實驗。三、實驗環(huán)境a)獨立計算機;b)Windows操作系統(tǒng);c)Jdk工具包四、實驗原理SocketAPI是一種作為IPC提供低層抽象的機制。盡管應(yīng)用人員很少需要在該層編寫代碼,但理解socketAPI非常重要,因為:1,高層設(shè)施是構(gòu)建于socketAPI之上的,即他們是利用socketAPI提供的操作來實現(xiàn);2,對于以響應(yīng)時間要求較高或運行于有限資源平臺上的應(yīng)用來說,socketAPI可能是最適合的。在Internet網(wǎng)絡(luò)協(xié)議體系結(jié)構(gòu)中,傳輸層上有UDP和TCP兩種主要協(xié)議,UDP允許使用無連接通信傳送,被傳輸報文稱為數(shù)據(jù)包。而TCP則允許面向連接的可靠通信,這種IPC稱為流式socket。Java為流式socketAPI提供兩類socket(1)式用于連接的連接socket(2)式用于數(shù)據(jù)交換的數(shù)據(jù)socket。五、實驗內(nèi)容1.構(gòu)建客戶端程序和服務(wù)器端程序都需要的MystreamSocket類,定義繼承自javaSocket的sendMessage和receiveMessage方法2.構(gòu)建客戶端程序(1)創(chuàng)建一個MyStreamsocket的實例對象,并將其指定接收服務(wù)器和端口號(2)調(diào)用該socket的receiveMessage方法讀取從服務(wù)器端獲得的消息3.構(gòu)建服務(wù)器端程序(1)構(gòu)建連接socket實例,并與指定的端口號綁定,該連接socket隨時偵聽客戶端的連接請求(2)創(chuàng)建一個MyStreamsocket的實例對象(3)調(diào)用MyStreamsocket的實例對象的sendMessage方法,進行消息反饋。六、實驗報告1.應(yīng)用程序的結(jié)構(gòu)圖,說明程序之間的關(guān)系;程序的偽代碼。公用服務(wù)功能:import.*;import.*;publicclassMystreamSocketextendsSocket{privateSocketsocket;privateBufferedReaderinput;privatePrintWriteroutput;ava:importclassClient{ publicstaticvoidmain(Stringargs[]){ try{ InetAddresshostname=("localhost"); MystreamSocketmss=newMystreamSocket(hostname,12345); ("我是客戶端,我請求連接!"); (); }catch(IOExceptione){ tart(); } }catch(IOExceptione){ 如何實現(xiàn)全雙工的流式socket通信答:服務(wù)端監(jiān)聽端口,每當(dāng)有一個連接請求發(fā)來時,就與其建立新的連接,然后利用其提供的功能進行通信。如何實現(xiàn)安全socketAPI答:注意在通信過程中的各種異常情況的捕獲與處理。3.如何實現(xiàn)1對多的并發(fā)答:在服務(wù)端使用多線程。實驗三客戶/服務(wù)器應(yīng)用開發(fā)一、實驗?zāi)康?.驗證daytime和echo程序,2.實現(xiàn)包socket支撐的C/S模式IPC機制3.實現(xiàn)流式socket支撐的C/S模式IPC機制二、預(yù)習(xí)與實驗要求1.預(yù)習(xí)實驗指導(dǎo)書及教材的有關(guān)內(nèi)容,了解daytime和echo要提供的具體服務(wù)內(nèi)容;2.復(fù)習(xí)包socket和流式socket的實現(xiàn)原理;3.實驗前認(rèn)真聽講,服從安排。盡可能獨立思考并完成實驗。三、實驗環(huán)境a)獨立計算機;b)Windows操作系統(tǒng)。c)Jdk工具包四、實驗原理C/S模式是主要的分布式應(yīng)用范型,其設(shè)計的目的是提供網(wǎng)絡(luò)服務(wù)。網(wǎng)絡(luò)服務(wù)指如daytime、telnet、ftp和WWW之類的允許網(wǎng)絡(luò)用戶共享資源的服務(wù)。要構(gòu)建C/S范型的應(yīng)用就必須解決以下一些關(guān)鍵問題:(1)如何通過會話實現(xiàn)多個用戶的并發(fā)問題(2)如何定義客戶和服務(wù)器在服務(wù)會話期間必須遵守的協(xié)議(3)服務(wù)定位問題(4)進程間通信和事件同步問題:語法、語義和響應(yīng)(5)數(shù)據(jù)表示問題在解決了這些問題的基礎(chǔ)上,C/S范型必須遵從3層結(jié)構(gòu)的軟件體系結(jié)構(gòu):(1)表示層,提供與客戶端進行交互的界面(2)應(yīng)用邏輯層,定義服務(wù)器和客戶端要處理的主要事務(wù)的業(yè)務(wù)邏輯(3)服務(wù)層,定義應(yīng)用邏輯層所需要的底層支持技術(shù),例如定義其IPC機制里的receive方法和send方法等。五、實驗內(nèi)容1.構(gòu)建用數(shù)據(jù)包socket實現(xiàn)的daytime客戶端程序(1)構(gòu)建表示層程序(2)構(gòu)建應(yīng)用邏輯層程序(3)構(gòu)建服務(wù)層程序2.構(gòu)建用數(shù)據(jù)包socket實現(xiàn)的daytime服務(wù)器端程序(1)構(gòu)建表示層和應(yīng)用邏輯層程序(2)構(gòu)建服務(wù)層程序(3)構(gòu)建服務(wù)層程序所需要的下層程序(它封裝了客戶端的消息和地址)3.構(gòu)建用流式socket實現(xiàn)的daytime應(yīng)用程序包4.構(gòu)建用數(shù)據(jù)包socket實現(xiàn)的echo應(yīng)用程序包5.構(gòu)建用流式socket實現(xiàn)的echo應(yīng)用程序包六、實驗報告1.用數(shù)據(jù)包socket實現(xiàn)的daytime應(yīng)用程序包的構(gòu)架,列明各程序之間的關(guān)系;客戶端:服務(wù)端:代碼:客戶端:import.*;

publicclassDaytimeClient1{

publicstaticvoidmain(String[]args){

InputStreamReaderis=newInputStreamReader;

BufferedReaderbr=newBufferedReader(is);

try{

"WelcometotheDaytimeclient.\n"+

"Whatisthenameoftheserverhost");

StringhostName=();

if()==0)

hostName="localhost";

;publicclassDaytimeClientHelper1{

publicstaticStringgetTimestamp(StringhostName,StringportNum){

Stringtimestamp="";

try{

InetAddressserverHost=(hostName);

intserverPort=(portNum);

;import.*;publicclassMyClientDatagramSocketextendsDatagramSocket{staticfinalintMAX_LEN=100;

MyClientDatagramSocket()throwsSocketException{

super();

}

MyClientDatagramSocket(intportNo)throwsSocketException{

super(portNo);

}

publicvoidsendMessage(InetAddressreceiverHost,intreceiverPort,Stringmessage)

throwsIOException{

byte[]sendBuffer=();

DatagramPacketdatagram=newDatagramPacket(sendBuffer,,

receiverHost,receiverPort);

(datagram);

}

publicStringreceiveMessage()

throwsIOException{

byte[]receiveBuffer=newbyte[MAX_LEN];

DatagramPacketdatagram=newDatagramPacket(receiveBuffer,MAX_LEN);

(datagram);

Stringmessage=newString(receiveBuffer);

returnmessage;

}}服務(wù)端:import.*;import

publicclassDaytimeServer1{

publicstaticvoidmain(String[]args){

intserverPort=13;

if==1)

serverPort=(args[0]);

try{

MyServerDatagramSocketmySocket=newMyServerDatagramSocket(serverPort);

"Daytimeserverready.");

while(true){

DatagramMessagerequest=();

"Requestreceived");

Datetimestamp=newDate();

"timestampsent:"+());

(),

(),());

}

}

catch(Exceptionex){

"Thereisaproblem:"+ex);

}

}}import.*;import.*;publicclassMyServerDatagramSocketextendsDatagramSocket{staticfinalintMAX_LEN=100;

MyServerDatagramSocket(intportNo)throwsSocketException{

super(portNo);

}

publicvoidsendMessage(InetAddressreceiverHost,intreceiverPort,Stringmessage)

throwsIOException{

byte[]sendBuffer=();

DatagramPacketdatagram=

newDatagramPacket(sendBuffer,,receiverHost,receiverPort);

(datagram);

}

publicStringreceiveMessage()

throwsIOException{

byte[]receiveBuffer=newbyte[MAX_LEN];

DatagramPacketdatagram=newDatagramPacket(receiveBuffer,MAX_LEN);

(datagram);

Stringmessage=newString(receiveBuffer);

returnmessage;

}

publicDatagramMessagereceiveMessageAndSender()

throwsIOException{

byte[]receiveBuffer=newbyte[MAX_LEN];

DatagramPacketdatagram=newDatagramPacket(receiveBuffer,MAX_LEN);

(datagram);

DatagramMessagereturnVal=newDatagramMessage();

(newString(receiveBuffer),(),

());

returnreturnVal;

}}import.*;publicclassDatagramMessage{

privateStringmessage;

privateInetAddresssenderAddress;

privateintsenderPort;

publicvoidputVal(Stringmessage,InetAddressaddr,intport){

=message;

=addr;

=port;

}

publicStringgetMessage(){

return;

}

publicInetAddressgetAddress(){

return;

}

publicintgetPort(){

return;

}}用流式socket實現(xiàn)的daytime應(yīng)用程序包的構(gòu)架,列明各程序之間的關(guān)系;客戶端:服務(wù)端:共有的:import.*;import.*;publicclassMyStreamSocketextendsSocket{privateSocketsocket;privateBufferedReaderinput;privatePrintWriteroutput;MyStreamSocket(InetAddressacceptorHost,intacceptorPort)throwsSocketException,IOException{socket=newSocket(acceptorHost,acceptorPort);setStreams();}MyStreamSocket(Socketsocket)throwsIOException{=socket;setStreams();}privatevoidsetStreams()throwsIOException{InputStreaminStream=();input=newBufferedReader(newInputStreamReader(inStream));OutputStreamoutStream=();output=newPrintWriter(newOutputStreamWriter(outStream));}publicvoidsendMessage(Stringmessage)throwsIOException{(message);();}publicStringreceiveMessage()throwsIOException{Stringmessage=();returnmessage;}}客戶端:import.*;publicclassDaytimeClient2{

publicstaticvoidmain(String[]args){

InputStreamReaderis=newInputStreamReader;

BufferedReaderbr=newBufferedReader(is);

try{

"WelcometotheDaytimeclient.\n"+

"Whatisthenameoftheserverhost");

StringhostName=();

if()==0)

hostName="localhost";

"Whatistheportnumberoftheserverhost");

StringportNum=();

if()==0)

portNum="13";

"Hereisthetimestampreceivedfromtheserver"

+(hostName,portNum));

}

catch(Exceptionex){

();

}

}}

import.*;publicclassDaytimeClientHelper2{

publicstaticStringgetTimestamp(StringhostName,

StringportNum)throwsException{

Stringtimestamp="";

InetAddressserverHost=(hostName);

intserverPort=(portNum);

"Connectionrequestmade");

MyStreamSocketmySocket=newMyStreamSocket(serverHost,serverPort);

timestamp=();

();

returntimestamp;

}}服務(wù)端:import.*;import.*;import

publicclassDaytimeServer2{

publicstaticvoidmain(String[]args){

intserverPort=13;

if==1)

serverPort=(args[0]);

try{

ServerSocketmyConnectionSocket=newServerSocket(serverPort);

"Daytimeserverready.");

while(true){

"Waitingforaconnection.");

MyStreamSocketmyDataSocket=newMyStreamSocket

());

"Aclienthasmadeconnection.");

Datetimestamp=newDate();

"timestampsent:"+());

());

();

}

}

catch(Exceptionex){

();

}

}}用數(shù)據(jù)包socket實現(xiàn)的echo應(yīng)用程序包的構(gòu)架,列明各程序之間的關(guān)系;客戶端:import.*;publicclassEchoClient1{

staticfinalStringendMessage=".";

publicstaticvoidmain(String[]args){

InputStreamReaderis=newInputStreamReader;

BufferedReaderbr=newBufferedReader(is);

try{

"WelcometotheEchoclient.\n"+

"Whatisthenameoftheserverhost");

StringhostName=();

if()==0)

hostName="localhost";

"Whatistheportnumberoftheserverhost");

StringportNum=();

if()==0)

portNum="7777";

EchoClientHelper1helper=newEchoClientHelper1(hostName,portNum);

booleandone=false;

Stringmessage,echo;

while(!done){

"Enteralinetoreceiveanechobackfromtheserver,"

+"orasingleperoidtoquit.");

message=();

if(()).equals(endMessage)){

done=true;

();

}

else{

echo=(message);

}

}

}

catch(Exceptionex){

();

}

}}

import.*;import.*;publicclassEchoClientHelper1{

privateMyClientDatagramSocketmySocket;

privateInetAddressserverHost;

privateintserverPort;

EchoClientHelper1(StringhostName,StringportNum)

throwsSocketException,UnknownHostException{

=(hostName);

=(portNum);

=newMyClientDatagramSocket();

}

publicStringgetEcho(Stringmessage)

throwsSocketException,IOException{

Stringecho="";

(serverHost,serverPort,message);

echo=();

returnecho;

}

publicvoiddone()throwsSocketException{

();

}

}import.*;import.*;publicclassMyClientDatagramSocketextendsDatagramSocket{staticfinalintMAX_LEN=100;

MyClientDatagramSocket()throwsSocketException{

super();

}

MyClientDatagramSocket(intportNo)throwsSocketException{

super(portNo);

}

publicvoidsendMessage(InetAddressreceiverHost,intreceiverPort,Stringmessage)

throwsIOException{

byte[]sendBuffer=();

DatagramPacketdatagram=newDatagramPacket(sendBuffer,,

receiverHost,receiverPort);

(datagram);

}

publicStringreceiveMessage()

throwsIOException{

byte[]receiveBuffer=newbyte[MAX_LEN];

DatagramPacketdatagram=newDatagramPacket(receiveBuffer,MAX_LEN);

(datagram);

Stringmessage=newString(receiveBuffer);

returnmessage;

}}服務(wù)端:import.*;publicclassEchoServer1{

publicstaticvoidmain(String[]args){

intserverPort=1117;

if==1)

serverPort=(args[0]);

try{

MyServerDatagramSocketmySocket=newMyServerDatagramSocket(serverPort);

"Echoserverready.");

while(true){

DatagramMessagerequest=();

"Requestreceived");

Stringmessage=();

"messagereceived:"+message);

(),

(),message);

}

}

catch(Exceptionex){

();

}

}}import.*;import.*;publicclassMyServerDatagramSocketextendsDatagramSocket{staticfinalintMAX_LEN=100;

MyServerDatagramSocket(intportNo)throwsSocketException{

super(portNo);

}

publicvoidsendMessage(InetAddressreceiverHost,intreceiverPort,Stringmessage)

throwsIOException{

byte[]sendBuffer=();

DatagramPacketdatagram=

newDatagramPacket(sendBuffer,,receiverHost,receiverPort);

(datagram);

}

publicStringreceiveMessage()

throwsIOException{

byte[]receiveBuffer=newbyte[MAX_LEN];

DatagramPacketdatagram=newDatagramPacket(receiveBuffer,MAX_LEN);

(datagram);

Stringmessage=newString(receiveBuffer);

returnmessage;

}

publicDatagramMessagereceiveMessageAndSender()

throwsIOException{

byte[]receiveBuffer=newbyte[MAX_LEN];

DatagramPacketdatagram=newDatagramPacket(receiveBuffer,MAX_LEN);

(datagram);

DatagramMessagereturnVal=newDatagramMessage();

(newString(receiveBuffer),(),

());

returnreturnVal;

}}import.*;publicclassDatagramMessage{

privateStringmessage;

privateInetAddresssenderAddress;

privateintsenderPort;

publicvoidputVal(Stringmessage,InetAddressaddr,intport){

=message;

=addr;

=port;

}

publicStringgetMessage(){

return;

}

publicInetAddressgetAddress(){

return;

}

publicintgetPort(){

return;

}}用流式socket實現(xiàn)的echo應(yīng)用程序包的構(gòu)架,列明各程序之間的關(guān)系。共有的:import.*;import.*;publicclassMyStreamSocketextendsSocket{privateSocketsocket;privateBufferedReaderinput;privatePrintWriteroutput;MyStreamSocket(InetAddressacceptorHost,intacceptorPort)throwsSocketException,IOException{socket=newSocket(acceptorHost,acceptorPort);setStreams();}MyStreamSocket(Socketsocket)throwsIOException{=socket;setStreams();}privatevoidsetStreams()throwsIOException{InputStreaminStream=();input=newBufferedReader(newInputStreamReader(inStream));OutputStreamoutStream=();output=newPrintWriter(newOutputStreamWriter(outStream));}publicvoidsendMessage(Stringmessage)throwsIOException{(message);();}publicStringreceiveMessage()throwsIOException{Stringmessage=();returnmessage;}}客戶端:import.*;publicclassEchoClient2{

staticfinalStringendMessage=".";

publicstaticvoidmain(String[]args){

InputStreamReaderis=newInputStreamReader;

BufferedReaderbr=newBufferedReader(is);

try{

"WelcometotheEchoclient.\n"+

"Whatisthenameoftheserverhost");

StringhostName=();

if()==0)

hostName="localhost";

"Whatistheportnumberoftheserverhost");

StringportNum=();

if()==0)

portNum="7";

EchoClientHelper2helper=newEchoClientHelper2(hostName,portNum);

booleandone=false;

Stringmessage,echo;

while(!done){

"Enteralinetoreceiveanecho"

+"fromtheserver,orasingleperiodtoquit.");

message=();

if(()).equals(endMessage)){

done=true;

();

}

else{

echo=(message);

}

}

}

catch(Exceptionex){

();

}

}}import.*;import.*;publicclassEchoClientHelper2{

staticfinalStringendMessage=".";

privateMyStreamSocketmySocket;

privateInetAddressserverHost;

privateintserverPort;

EchoClientHelper2(StringhostN

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論