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

上传人:txadgkn****dgknqu... 文档编号:252554783 上传时间:2024-11-17 格式:PPT 页数:43 大小:342.85KB
返回 下载 相关 举报
分布式计算原理与应用(Distributed-Computing)第四章课件_第1页
第1页 / 共43页
分布式计算原理与应用(Distributed-Computing)第四章课件_第2页
第2页 / 共43页
分布式计算原理与应用(Distributed-Computing)第四章课件_第3页
第3页 / 共43页
点击查看更多>>
资源描述
Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,*,Distributed Computing,M.L.Liu,*,The Socket API,Mei-Ling Liu,11/17/2024,1,Distributed Computing,M.L.Liu,The Socket APIMei-Ling Liu10/6,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 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.,11/17/2024,2,Distributed Computing,M.L.Liu,IntroductionThe socket API is,The conceptual model of the socket API,11/17/2024,3,Distributed Computing,M.L.Liu,The conceptual model of the so,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 and receive data.,11/17/2024,4,Distributed Computing,M.L.Liu,The socket APIA socket API pro,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 sockets,.,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.,11/17/2024,5,Distributed Computing,M.L.Liu,Connection-oriented&connecti,Connection-oriented&connectionless datagram socket,Datagram sockets can support both,connectionless,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 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.),11/17/2024,6,Distributed Computing,M.L.Liu,Connection-oriented&connecti,Connection-oriented&connectionless datagram socket,11/17/2024,7,Distributed Computing,M.L.Liu,Connection-oriented&connecti,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 a socket in short.Each socket is said to be,bound,to a UDP port of the machine local to the process,11/17/2024,8,Distributed Computing,M.L.Liu,The Java Datagram Socket APII,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 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,DatagramPacket,object as an argument,11/17/2024,9,Distributed Computing,M.L.Liu,The Java Datagram Socket APITo,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 datagrams 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.,11/17/2024,10,Distributed Computing,M.L.Liu,The Java Datagram Socket API I,The Data Structures in the sender and receiver programs,11/17/2024,11,Distributed Computing,M.L.Liu,The Data Structures in the sen,The program flow in the sender and receiver programs,11/17/2024,12,Distributed Computing,M.L.Liu,The program flow in the sender,Event synchronization with the connectionlss datagram socketsAPI,11/17/2024,13,Distributed Computing,M.L.Liu,Event synchronization with the,Setting timeout,To avoid indefinite 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.,11/17/2024,14,Distributed Computing,M.L.Liu,Setting timeoutTo avoid indef,Key Methods and Constructors,11/17/2024,15,Distributed Computing,M.L.Liu,Key Methods and Constructors10,The coding,11/17/2024,16,Distributed Computing,M.L.Liu,The coding 10/6/202316Distribu,Connectionless sockets,With connectionless sockets,it is possible for multiple
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 教学培训


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!