Distributed Systems Programming Sockets: On TCP/IP Networks
Distributed Systems Programming Sockets: On TCP/IP Networks
Sockets
Low-level communication interface (API) Network Programming Defined 1981Bolt, Beranek and Newman (BBN) Originally developed for the C language TCP/IP version with Unix called BSD sockets Similar API was developed for System V a.k.a TLI To some extent similar to file IO
Sockets
What is a socket?
It is a peer-to-peer communication endpoint abstraction Hides details of network for programming communication situations Interfaces to some common network protocols (e.g. TCP, UDP, XNS, NetBIOS, IP, etc.)
Socket types
Three types:
Stream (e.g. interface to TCP),
session based reliable service that takes care of connection maintenance, packet reassembly, etc. Mimics UNIX file system semantics
Socket Ports
On TCP/IP networks:
Socket = Internet Address(IP) + Port Address IP is a 32 bit number using dotted string notation, e.g., 206.10.47.09. Port is an entry point to an application that resides on a host.
Commonly used and defined for server applications
Sockets
To initiate a connection one must fix the roles: client or server A network connection can be connection-oriented or connectionless
With a connectionless protocol there is nothing like an Open communication; every network IO operation can be with different process/host In a connection based operation a peer-to-peer channel is opened
Connection-oriented use
Connection is first established between client and server System Calls at server side
socket() // creates endpoint, specify protocol (TCP, UDP, XNS, etc.), specify type (i.e. stream, datagram, etc.) Returns a small integer similar to file descriptor. bind() // register and bound network address to socket listen() // signal willing to receive connections accept() // accept a connection read(), write() // transfer data
Connection-oriented protocol
Client side
socket() // same meaning as in server connect() //establish contact between local-remote site read() write() //transfer data
Blocks Until connect
read()
Data (reply)
write() read()
write()
socket() bind()
Data(request)
sendto() recvfrom()
Data (reply)
sendto()
Use of the sendto() and recvfrom() as opposed to the read() and write() system calls The client registers an address for itself with the bind() to be able to receive messages back (this address is sent with data automatically)
Java sockets
Semantics the same as we discussed earlier Java.net contains most of the classes needed Java.io contains socket related stream classes
A socket may be associated with a stream in Java (provided by the Socket class implementation) Streams are fun as they hide devices, its like a data pipe You can use OutputStream, InputStream, and other stream classes derived from these with sockets. Somewhat similar to what you have seen with file access.
Before RMI and CORBA support has been designed for Java this was the only way to do network programming Java.net package contains
Set of classes that let you download and manipulate URL objects A native Java implementation of Berkeley (BSD) sockets
Summary Sockets
Abstraction for network programming. Java provides a nice implementation. Many known high-level protocols use sockets as underlying communication mechanisms. Disadvantages:
lots of details to address, many parameters to control. Requires understanding of system issues and network protocols
CORBA
Programming distributed systems and services Objective of this class is to give you an idea of CORBA capabilities and programming approach
Advantage:
Best performance in distributed applications, fine-tuning opportunities.
What is CORBA?
CORBA = Common Object Request Broker Architecture What is CORBA:
A middleware or intermediate software layers that allow heterogeneous client and server applications to communicate in a distributed system. CORBA works with distributed systems written in : C,C++,COBOL, Java, or ADA... Provides a suite of pre-built complex services An API that allows programmers to build complex distributed services This, as opposed to
Sockets that is a low level network programming API Java RMI that works with Java clients and servers only, it is a Java-to-Java technology and used only for network programming.
CORBA is similar to Java J2EE based application servers and Microsoft .net
CORBA implementations
OMG produces specification not code. Various vendors such as Iona, Oracle, Sun, IBM, Inprise (Borland), ... have their own CORBA implementations.
http://www.corba.org/vc.htm
CORBA IDL
IDL=Interface Definition Language Can be seen as a generic programming language to write standard interfaces for a distributed application
it also allows a CORBA service or server to describe itself in a standard way, independent of actual implementation/OS/prog language used
CORBA ORB
The ORB forms the backbone of CORBA It is also called the Object Bus
It allows clients to invoke methods on distributed objects and accept return values. There is an ORB on both the client and the server side. Clients and servers can be distributed on a network or located in the same machine. When a client requests a reference for a remote object, the client ORB needs to find the remote object.
CORBA services
Component providers develop their objects without concern for system services, which is provided by the CORBA services CORBA services provide a unique approach for build-to-order middleware.
Think of services as augmenting the ORBs. Each service is packaged with its own IDL interface.
In practice (depending on programming language), when a service is required, then the component providers just subclass the original service classes; service is provided by inheritance
For example, a component called my_account can be mixed with CORBA services to create a concurrent, persistent, transactional version of my_account...
IIOP
CORBA facilities
Are collections of IDL-defined frameworks for applications Next step up semantically from the services Example
data interchange, business object frameworks, internationalization, distributed documents, systems management, information management, ...
Steps 1-4
1. Define objects using IDL. This is how objects tell clients what operations are available and how they should be invoked 2. Run IDL file through precompiler
e.g., in Java: prompt> idl2java count.idl produces skeletons for the server
Skeletons
3 5
Interface Repository
Client IDL Stubs
Compile
Server IDL Skeletons
tia ta n ins
7e
t
Object Adapter
3. Add the implementation code to the skeletons 4. Compile the code - with a CORBA-compliant compiler that is typically capable of generating three types of output files:
6
Implementation Repository
Object Implementation
1) import files - describe the objects to an Interface Repository 2) client stubs - these are invoked by client programs that need to statically access IDL-defined services via ORB 3) server skeletons - that actually call the methods on the server
Client
Server
Steps 5-7
5. Bind the class definitions to the interface repository.
Typically, you use a utility to bind.
Summary
CORBA - a middleware for heterogeneous distributed computing Main Components: IDL, ORB, IIOP CORBA provides services,e.g., life-cycle management, events, etc., that can be leveraged in applications.
IIOP
Java
Java client
Some ORB for Java IIOP
SERVER
C++ ORB for C++