Interprocess communication (Part 2) For an application to send something out as a message, it must arrange its OS to receive its input. The OS is then sends it out either as a UDP datagram on the transport layer or as TCP stream on the transport layer. This is done via a socket. Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.net For communication purpose: A socket is System 1 System 2 Client Socket IP: A Server Socket Port: x IP: B Client process: (creates socket at OS, connect socket to server address B at port x using connect( ), send to and receive from server socket using, say, read( ) and write( ) system commands)
Server process: (creates socket at OS, bind the socket to an address and a port number, issue listen ( ), if a connection appears call accept( ), send and receive data) Every socket is endowed with socket type, and address domain. Socket types: stream socket (TCP) or datagram socket (UDP) Address domain: Unix domain or Internet domain Berkeley sockets are the most popular Internet socket Runs on FreeBSD, Linux, Windows using TCP/IP protocol. Stream sockets. Connection oriented Two-way communications Reliable (order is maintained at the reception) Uses TCP e.g. Telent, ssh, http applications Datagram sockets: Connection less. Open connection is not maintained Uses UDP, no delivery guarantee e.g. skype
Client-Server sockets Request Client Server Response socket() bind () socket() listen() connect() Establish connection accept() send() Data request recv() recv() close() Data response Close the session send() recv() close() Example. Client socket. ๐ Create socket socket() ๐ Connect to server connect() ๐ While still connected send msg to server send() receive msg from server recv() ๐ Close TCP connection and socket close()
Naming and Name-server Objects and entities in DS must have names and locations in order to communicate. Name provides an access point. Access point: www.sunyit.edu Access point of a process at a transport level: (IP address, port) Access level of a machine at Data Link layer: mac address Using address to refer to an entity is not human friendly. Address may even change. Therefore, a mnemonic like: spirrowa@fang.cs.sunyit.edu. This is a location independent access point a better design. Name types: Identifier Address Human friendly name Names could be flat without assuming any structure. Names could be hierarchically structured. Name server s job is to aid in the mapping, Name resolver: name location. Name server As in a LAN. A station wants to know the Mac address of an entity with a specific IP address. Station uses ARP protocol to resolve the issue at the Domain Name Server (DNS). Local DNS may not have the mapping of a specific address to a location. In that case, DNS may try it at a root server to resolve the issue. Root server needs to be replicated.
Thus for a name server, several solutions may exist to locate an entity Broadcasting solution (not feasible in large network) Forwarding pointers Home based solution Hierarchical solution Distributed Hash-table Forwarding pointer: I know A s location now. A moves to some other location, and it leaves a pointer to its new location with me. Ideal for mobile objects. Problem: long chains of pointers. Prone to failures. Home based solution: Each mobile object has a home it could refer to. Moving away to a foreign domain is handled in this manner: what-when-how.com This is a popular method for Mobile IP. Normally a tunnel would be used to transfer packets from Home domain to the foreign agent at the foreign domain.
Hierarchical solution via a root server If it cannot be located at a local DNS, the enquiry is passed to the root DNS for resolution. Another mode of communication in distributed system is RPC Remote Procedure Call. Here the idea is to avoid direct message passing from one process to another. Instead a process makes a procedure call in a remote machine making it as if it is a local call. In an RPC parameters are passed as value parameters by the client stub to the server. The server unpacks the client stub, carries out the procedure locally, and packs the result into the server stub, and sends it to client.
Packing arguments in a stub is called marshalling process. The arguments are passed as value parameters. A. Birrell, B Nelson, Implementing Remote Procedure Calls, ACM Symposium on Operating System Principles, 1984 In RPC, the value parameters are passed to the remote procedure.
In RMI, Remote Method Indication, JVM can access a remote object in another machine and run one of its methods (remotely) using parameter passing by reference. Basically, Local objects This machine invoke receive Remote objects Remote machine Java RMI allows interacting with distributed objects at remote servers. Local clients are usually thin clients invoking services at the top-heavy servers. The constraint: Language dependent. Basically it is a totally Java solution. Basic architecture: (almost like RPC) Client Server Stubs Skeletons Remote Reference Reference Instantiate an object of interest in another machine Invoke one of its methods.