分布式计算原理与应用(DistributedComputing)第四章ppt课件.ppt
《分布式计算原理与应用(DistributedComputing)第四章ppt课件.ppt》由会员分享,可在线阅读,更多相关《分布式计算原理与应用(DistributedComputing)第四章ppt课件.ppt(43页珍藏版)》请在三一办公上搜索。
1、3/31/2023,Distributed Computing,M.L.Liu,1,The Socket API,Mei-Ling Liu,3/31/2023,Distributed Computing,M.L.Liu,2,Introduction,The socket API is an Interprocessing Communication(IPC)programming interface originally provided as part of the Berkeley UNIX operating system.It has been ported to all modern
2、 operating systems,including Sun Solaris and Windows systems.It is a de facto standard for programming IPC,and is the basis of more sophisticated IPC interface such as remote procedure call and remote method invocation.,3/31/2023,Distributed Computing,M.L.Liu,3,The conceptual model of the socket API
3、,3/31/2023,Distributed Computing,M.L.Liu,4,The socket API,A socket API provides a programming construct termed a socket.A process wishing to communicate with another process must create an instance,or instantiate,such a construct The two processes then issues operations provided by the API to send a
4、nd receive data.,3/31/2023,Distributed Computing,M.L.Liu,5,Connection-oriented&connectionless datagram socket,A socket programming construct can make use of either the UDP or TCP protocol.Sockets that use UDP for transport are known as datagram sockets,while sockets that use TCP are termed stream so
5、ckets.Because of its relative simplicity,we will first look at datagram sockets,returning to stream sockets after we have introduced the client-server model in Chapter 5.,3/31/2023,Distributed Computing,M.L.Liu,6,Connection-oriented&connectionless datagram socket,Datagram sockets can support both co
6、nnectionless and connection-oriented communication at the application layer.This is so because even though datagrams are sent or received without the notion of connections at the transport layer,the runtime support of the socket API can create and maintain logical connections for datagrams exchanged
7、 between two processes,as you will see in the next section.(The runtime support of an API is a set of software that is bound to the program during execution in support of the API.),3/31/2023,Distributed Computing,M.L.Liu,7,Connection-oriented&connectionless datagram socket,3/31/2023,Distributed Comp
8、uting,M.L.Liu,8,The Java Datagram Socket API,In Java,two classes are provided for the datagram socket API:the DatagramSocket class for the sockets.the DatagramPacket class for the datagram exchanged.A process wishing to send or receive data using this API must instantiate a DatagramSocket object,or
9、a socket in short.Each socket is said to be bound to a UDP port of the machine local to the process,3/31/2023,Distributed Computing,M.L.Liu,9,The Java Datagram Socket API,To send a datagram to another process,a process:creates an object that represents the datagram itself.This object can be created
10、by instantiating a DatagramPacket object which carries(i)the payload data as a reference to a byte array,and(ii)the destination address(the host ID and port number to which the receivers socket is bound.issues a call to a send method in the DatagramSocket object,specifying a reference to the Datagra
11、mPacket object as an argument,3/31/2023,Distributed Computing,M.L.Liu,10,The Java Datagram Socket API,In the receiving process,a DatagramSocket object must also be instantiated and bound to a local port,the port number must agree with that specified in the datagram packet of the sender.To receive da
12、tagrams sent to the socket,the process creates a datagramPacket object which references a byte array and calls a receive method in its DatagramSocket object,specifying as argument a reference to the DatagramPacket object.,3/31/2023,Distributed Computing,M.L.Liu,11,The Data Structures in the sender a
13、nd receiver programs,3/31/2023,Distributed Computing,M.L.Liu,12,The program flow in the sender and receiver programs,3/31/2023,Distributed Computing,M.L.Liu,13,Event synchronization with the connectionlss datagram socketsAPI,3/31/2023,Distributed Computing,M.L.Liu,14,Setting timeout,To avoid indefin
14、ite blocking,a timeout can be set with a socket object:void setSoTimeout(inttimeout)Set a timeout for the blocking receive from this socket,in milliseconds.Once set,the timeout will be in effect for all blocking operations.,3/31/2023,Distributed Computing,M.L.Liu,15,Key Methods and Constructors,3/31
15、/2023,Distributed Computing,M.L.Liu,16,The coding,3/31/2023,Distributed Computing,M.L.Liu,17,Connectionless sockets,With connectionless sockets,it is possible for multiple processes to simultaneously send datagrams to the same socket established by a receiving process,in which case the order of the
16、arrival of these messages will be unpredictable,in accordance with the UDP protocol,3/31/2023,Distributed Computing,M.L.Liu,18,Code samples,Example1Sender.java,ExampleReceiver.javaMyDatagramSocket.java,Example2SenderReceiver.java,Example2ReceiverSender.java,3/31/2023,Distributed Computing,M.L.Liu,19
17、,Connection-oriented datagram socket API,It is uncommon to employ datagram sockets for connection-oriented communication;the connection provided by this API is rudimentary and typically insufficient for applications that require a true connection.Stream-mode sockets,which will be introduced later,ar
18、e more typical and more appropriate for connection-oriented communication.,3/31/2023,Distributed Computing,M.L.Liu,20,Methods calls for connection-oriented datagram socket,A connection is made for a socket with a remote socket.Once a socket is connected,it can only exchange data with the remote sock
19、et.If a datagram specifying another address is sent usingthe socket,an IllegalArgumentException will occur.If a datagram from another socket is sent to this socket,The data will be ignored.,3/31/2023,Distributed Computing,M.L.Liu,21,Connection-oriented Datagram Socket,The connection is unilateral,th
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 分布式 计算 原理 应用 DistributedComputing 第四 ppt 课件
链接地址:https://www.31ppt.com/p-4000481.html