Message Passing Models II ========================= UNIX sockets ============ Message passing on the operating system level Introduced in Unix BSD 4.2 Based on Internet Protocol (TCP/IP, UDP/IP) Client Server Model - client process creates socket at one end of communication link - server process responds through a socket at the other side of link Relationship not symmetrical - application must know whether it is server or client SLIDE ptx sockets manual, Figure 1-1 Basic Strategy -------------- SLIDE ptx sockets manual, Figure 4-1 1. server creates socket process internal data structure 2. bind() assigns address to socket server can advertise location of its service 3. server issues listen() to indicate that it is ready to receive connection requests 4. server issues accept() to handle each connection request 5. client creates socket 6. client issues connect() to establish connection with server 7. client issues write() to send request to server 8. server issues read() to accept request from client 9. server issues write() to send reply to client Multithreading -------------- 8. server starts thread and passes socket to thread - detached thread receives and replies to request 9. server goes to step 4 Example Programs ---------------- SLIDE ptx sockets manual, page 4.5 - TCP server - TCP client Remote Procedure Calls (RPC) ============================ "Synchronous message passing" Communication by procedure calls - creates a request and blocks until reply is received - lower layers care for data conversions and communication - interface language required to provide semantics of parameter passing mechanisms SLIDE ptx/NFS RPC programming guide, Figure 1-1 SLIDE ptx/NFS RPC programming guide, page 1-3 RPC program SLIDE ptx/NFS RPC programming guide, page 1-5 SLIDE ptx/NFS RPC programming guide, page 1-6 SLIDE ptx/NFS RPC programming guide, page 1-7 rpcgen: a protocol compiler Generation of RPC programs from sequential code - takes remote program interface definition in RPC language - produces C output which includes - stub versions of client routines - server skeleton - filter routines for parameters Developer writes server procedures and links them with server skeleton => executable server program User writes main program that makess local procedure calls to client stubs produced by rpcgen => executable client program SLIDE ptx/RPC rpcgen programming guide, page 2-3 SLIDE ptx/RPC rpcgen programming guide, page 4 SLIDE ptx/RPC rpcgen programming guide, page 5 SLIDE ptx/RPC rpcgen programming guide, page 6-8 World Wide Web (WWW) ==================== Networks of servers providing hypertext documents Client browsers request document from server Server provides document Client browser displays document Request may trigger any action on server - start of program - access of database - .... => result document may be generated on the fly Accessing any server functionality over the WWW Java ==== C++ like programming language developed by SUN Compiler generates portable byte code WWW browsers incorportate interpreter for byte code HTML document may contain references to byte code "Applets" Applets are loaded from server and executed by browser "Executable documents" => documents become applications "Network computers" => operating system becomes browser/document interpreter Examples -------- Implementing a (multithreaded) Server SLIDE Java in a Nutshell, page 145-146 (Object oriented parallel programming, see later) Implementing a client SLIDE Java in a Nutshell, page 147-148 Implementing an applet client SLIDE Java in a Nutshell, page 149-150 Future ------ Extensions: server-side applets "servlets" - client may return code to server for execution Extensions: mobile agents - programs "wandering" through the network