180 likes | 327 Views
CS490T Advanced Tablet Platform Applications. Network Programming Evolution. Introduction. Programming network applications has evolved with programming languages Tools have been created at each step to make distributed applications as easy as writing local applications. BSD Sockets.
E N D
CS490T Advanced Tablet Platform Applications Network Programming Evolution
Introduction • Programming network applications has evolved with programming languages • Tools have been created at each step to make distributed applications as easy as writing local applications.
BSD Sockets • Network sockets were introduced in the UNIX Berkeley Standard Distributions (BSD UNIX) • They provided a common API to the TCP/IP stacks • They were written generically enough to be used for other protocols different than TCP/IP. That made them awkward to use.
BSD Sockets • They were very successful because they provided a portability path for network applications. • An application written with sockets can be easily ported to other UNIX systems or Windows. • Sockets provide a • Stream interface for TCP • Message based interface for UDP
TCP Sockets • In the stream interface for TCP reading/writing to the other network peer will be similar to reading/writing to a file or pipe.
TCP Sockets Server Side • The server does: • Ms = Socket(…) – creates socket • Bind(…) – bind socket to a specific port • Listen(…) – puts socket in listen mode • While(1) { • ss = accept(ms, …) // Accept connection read(ss, …) // Read request • write(ss, …) // Write reply • }
TCP Sockets Client Side • The client does the following s= socket(…) // Creat socket bind(s, …) // Bind socket to a port connect(s) // Connect to server write(s, …) // Write requestread(s,…) // Read reply close(s)
Disadvantage of Socket Programming • Too complicated • Error prone. So many calls, so many possibilities of error. • Every communication detail has to be explicitly programmed.
Examples of Socket Applications • Lots of applications are implemented using sockets: • FTP, SMTP, Finger, HTTP, …
Remote Procedure Calls (RPC) • Abstract the network communication as a procedure call. • A program uses a method exported remotely as if it were local. • The interface of the procedure is described in a RPC description language. • The RPC description is processed with an RPC preprocessor that generates code for the client and the server.
RPCs Client Side • For the client side the code generated includes procedure stubs that • Defines the procedure with the same arguments • Connects to the remote server • Takes the arguments and send them through the network (marshaling). • Waits for a reply • Copies the result to the result of the procedure and returns. • The programmer uses these stubs transparently as if the procedures were executed locally.
RPC Server Side • The RPC processor generates for the server a dispatcher server code that • Initializes the sockets • Starts the serving loop waiting for a new request • When a request arrives it copies the data from the network to the argument buffer (unmarshalling) • It invokes the procedure corresponding to the RPC id. • It sends the results of the procedure to the other side (marshaling) • The programmer of the server only implements the procedures themselves. The communication part is generated by the RPC processor.
RPC Issues • The representation of numbers, strings etc. may be different in different machines. • In sockets that is not usually a problem since the communication is textually based in ASCII format. • In RPCs the data is sent in binary form. This saves processing time since no ASCII to decimal conversion is necessary but may cause problems in machines of different architecture. • The RPC generator also generates filters that convert the binary data if necessary.
RPC Issues • In SUN RPC, the data is always converted to an External Data Representation (XDR) before sending. • The data is converted back to the representation of the local machine when received. • In RPC’s arguments and results can be passed only by value (int, string, float etc) • It is not possible to send data by reference (Object *this) so it is not easy to write object oriented programs.
RPC Examples • The best known implementation of RPC’s is SUNRPC • SUNRPC defines an RPC language and provides an RPC processor called RPCgen • Applications such as NFS, rusers, mount, yellow pages are implemented in SUN RPC.
Remote Method Invocation (RMI) • It was created because of the limitations that RPC has handling references to objects. • In RMI a reference to a remote object is represented as a pointer to a local representation to the object called “Proxy”. • A method invocation to the proxy is forwarded to the remote object. • Invoking methods in the proxy will be transparent and it will look like we are invoking methods in the object as if it were local.
Proxy Creation/Deletion • When a reference to a remote object is received, a new proxy is created. • When the reference to the remote object is no longer needed, the proxy is deleted. • Some cooperation from the local garbage collector is needed to identify unneeded proxies. • Remote objects are removed when tere are no longer remote proxies pointing to it.
RMI Examples • The proxy code is generated by a processor from a RMI description. • Some examples of RMI are: Java RMI, CORBA Orbix, DCOM, Modula 3 Remote Objects.