分布式计算原理与应用(Distributed Computing)第五章课件(2)

上传人:油条 文档编号:26855486 上传时间:2018-01-02 格式:PPT 页数:24 大小:106.50KB
返回 下载 相关 举报
分布式计算原理与应用(Distributed Computing)第五章课件(2)_第1页
第1页 / 共24页
分布式计算原理与应用(Distributed Computing)第五章课件(2)_第2页
第2页 / 共24页
分布式计算原理与应用(Distributed Computing)第五章课件(2)_第3页
第3页 / 共24页
分布式计算原理与应用(Distributed Computing)第五章课件(2)_第4页
第4页 / 共24页
分布式计算原理与应用(Distributed Computing)第五章课件(2)_第5页
第5页 / 共24页
点击查看更多>>
资源描述

《分布式计算原理与应用(Distributed Computing)第五章课件(2)》由会员分享,可在线阅读,更多相关《分布式计算原理与应用(Distributed Computing)第五章课件(2)(24页珍藏版)》请在金锄头文库上搜索。

1、Distributed Computing, M. Liu,1,The Client-Server Model part 2,M. L. Liu,Distributed Computing, M. Liu,2,Connectionless server vs. connection-oriented server,Distributed Computing, M. Liu,3,Connectionless vs. connection-oriented server,A connectionless server Uses a connectionless IPC API (e.g., con

2、nectionless datagram socket)Sessions with concurrent clients can be interleaved.A connection-oriented server Uses a connection-oriented IPC API (e.g. stream-mode socket )Sessions with concurrent clients can only be sequential unless the server is threaded,Distributed Computing, M. Liu,4,EchoServer 1

3、(connectionless) Excerpt,public class EchoServer1 public static void main(String args) / instantiates a datagram socket for both sending / and receiving data MyServerDatagramSocket mySocket = new MyServerDatagramSocket(serverPort); while (true) / forever loop DatagramMessage request = mySocket.recei

4、veMessageAndSender();String message = request.getMessage( );mySocket.sendMessage(request.getAddress( ), request.getPort( ), message); /end while,Distributed Computing, M. Liu,5,Concurrent client sessions with EchoServer1,Distributed Computing, M. Liu,6,EchoServer2 (Connection-oriented) excerpt,Serve

5、rSocket myConnectionSocket = new ServerSocket(serverPort); while (true) / forever loop MyStreamSocket myDataSocket = new MyStreamSocket (myConnectionSocket.accept( ); boolean done = false; while (!done) message = myDataSocket.receiveMessage( ); if (message.trim().equals (endMessage)myDataSocket.clos

6、e( ); done = true; /end if else myDataSocket.sendMessage(message); /end else /end while !done /end while forever,Distributed Computing, M. Liu,7,Two consecutive client sessions with echo server2,Distributed Computing, M. Liu,8,Iterative serversVs. Concurrent servers,Distributed Computing, M. Liu,9,C

7、oncurrent Server,A connection-oriented server can be threaded so that it can service multiple clients concurrently. Such a server is said to be a concurrent server.An unthreaded connection-oriented server is said to be an iterative server.,Distributed Computing, M. Liu,10,A Concurrent, Connection-or

8、iented Server,Distributed Computing, M. Liu,11,Sequence diagram EchoServer3,Distributed Computing, M. Liu,12,EchoServer3 (concurrent) excerpt,ServerSocket myConnectionSocket = new ServerSocket(serverPort); while (true) / forever loop MyStreamSocket myDataSocket = new MyStreamSocket (myConnectionSock

9、et.accept( ); Thread theThread = new Thread(new ServerThread(myDataSocket); theThread.start(); /end while forever,Distributed Computing, M. Liu,13,ServerThread.java excerpt,class ServerThread implements Runnable static final String endMessage = .; MyStreamSocket myDataSocket; EchoServerThread(MyStre

10、amSocket myDataSocket) this.myDataSocket = myDataSocket; public void run( ) boolean done = false; String message; try / put in here the logic for each client session while (!done) message = myDataSocket.receiveMessage( ); if (message.trim().equals (endMessage) myDataSocket.close( ); done = true; /en

11、d if else myDataSocket.sendMessage(message); /end else /end while !done / end try catch (Exception ex) /end run /end class,Distributed Computing, M. Liu,14,Echo3Server concurrent sessions,Distributed Computing, M. Liu,15,Server Thread class template,class ServerThread implements Runnable static fina

12、l String endMessage = .; MyStreamSocket myDataSocket; ServerThread(MyStreamSocket myDataSocket) this.myDataSocket = myDataSocket; public void run( ) boolean done = false; String message; try /add code here / end try catch (Exception ex) System.out.println(Exception caught in thread: + ex); /end run

13、/end class,Distributed Computing, M. Liu,16,Stateful servers vs. Stateless servers,Distributed Computing, M. Liu,17,Session State Information,For some protocols or applications, a server must maintain information specific to a client during its service session.Consider a network service such as file

14、 transfer. A file is typically transferred in blocks, requiring several rounds of data exchanges to complete the file transfer. The dialog during a session proceeds roughly as follows:Client: Please send me the file foo in directory someDir.Server: Okay. Here is block 1of the fileClient: Got it.Server. Okay. Here is block2 of the fileClient: Got it.Server. Okay. Here is block3 of the fileClient: Got it.,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号