Why Java for Network Applications - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Why Java for Network Applications

Description:

Heterogeneous networks work together at Java level (all Java homogeneity) ... file, ftp, http, news, telnet, gopher, WAIS. Hostname: ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 22
Provided by: bobma5
Category:

less

Transcript and Presenter's Notes

Title: Why Java for Network Applications


1
Why Java for Network Applications
  • Language features (concurrency, exceptions)
  • Built-in objects (information hiding)(better
    than UNIX and building your own)
  • Protocol handlers, content handlers
  • down load as needed
  • loading classes remotely
  • Heterogeneous networks work together at Java
    level (all Java homogeneity)
  • All the other stuff for modern applicationsGUI,
    databases, security, etc.
  • Performanceindividual CPU generally not the
    bottleneck

2
Basic Web Terms
  • TCP/IP - Transport Control Protocol / Internet
    Protocol
  • UDP - User Datagram Protocol
  • URL - Uniform Resource Locator
  • URI - Uniform Resource Identifier
  • URN - Uniform Resource Name (separate from
    location)
  • HTTP - HyperText Transfer Protocol
  • HTML - Hypertext Markup Language
  • SGML - Standard Generalized Markup Language
  • XML eXtensible Markup Language
  • MIME - Multipurpose Internet Mail Extensions
  • ASCII - American Standard Code for Information
    Interchange

3
Network Layers
  • Very simplified view

Application
Application
Logical Communication
Transport(TCP, UDP)
Transport(TCP, UDP)
IP Layer
IP Layer
Physical layer (bits on the wire) ISO Level 1
Net Head IP Head TCP Head App. Head
Data
4
IP Addressing
  • Four numbers, each 0..255, e.g.
    123.123.123.123(32 bits for now)
  • Class C address block
  • first three bytes specified, e.g. 123.123.123.
  • room for 254 addresses (0 and 255 special)
  • Domain names that are easier to remember and use
  • Domain Name Service (DNS) for name resolution
  • Multi-hosting (multiple domain names on one IP
    address)multi-homing (multiple IP addresses on
    one machine
  • localhost 127.0.0.1 local loopback address
  • Java program to find local address

5
URL- Uniform Resource Locator
  • protocol//hostnameport/path/filenamesection
  • Protocol \file, ftp, http, news, telnet,
    gopher, WAIS
  • Hostnamewww.pithecanthropus.com or
    123.123.123.123
  • Port 13 (daytime), 20 21 (ftp), 23 (telnet),
    25 (smtp/mail), 37 (time), 43 (whois), 79
    (finger), 80 (http), 110 (pop3/mail), 119
    (nntp/news), 1099 (RMI Registry) defined in
    /etc/services or windows\services

6
URL
  • protocol//hostnameport/path/filenamesection
  • Pathrelative to document root of server, not
    file system root
  • Filenameusual default index.html server has
    other options
  • Sectionnamed anchor in an HTML document(text
    bookmark)
  • relative and absolute URLs allow moving whole
    collections

7
java.net.URL
  • public final class URL extends Object implements
    Serializable
  • URL constructor formats match common usepublic
    URL (--) throws MalformedURLException(String
    spec)(String protocol, String host, int
    port, String file)(String protocol, String
    host, String file)(URL context, String spec)

8
URL Constructor Examples
  • try URL u1 new URL(http//www.x.com/a.html)
    catch (MalformedURLException e)
    System.err.println(e)
  • new URL(http, www.x.com, /a.htmlb)
  • new URL(http, www.x.com, 80, /a.html)
  • new URL(u1, other.html)/ example / import
    java.applet.AppletURL u new URL(getDocumentBase
    (), b.html)

9
GetURL Copies Files (see code)
  • URL url new URL(args0)
  • InputStream in url.openStream()
  • // InputStream in new FileInputStream(a.b)
  • OutputStream out
  • new FileOutputStream(args1)
  • byte buffer new byte4096
  • int bytes_read
  • while((bytes_read in.read(buffer)) ! -1)
  • out.write(buffer, 0, bytes_read)

10
Idea of sockets
  • Computer has (probably) one connection to the net
  • Logical ports subdivide that connection
  • Operating system, network communications driver
    listens and then passes the information to
    waiting programs (sockets)
  • Sockets are independent programs registered to
    receive data
  • Parallel on senders side
  • Sockets can be used for two-way communication
  • Form the foundation for network communication
  • Popularized in Berkeley UNIX as a unifying concept

11
Copy http with sockets
  • Socket soc new Socket(url.getHost(),
    url.getPort())
  • InputStream from soc.getInputStream()
  • PrintWriter to new PrintWriter(new
    OutputStreamWriter(soc.getOutputStream()))
  • to.println("GET " filename) to.flush()
  • byte buffer new byte4096
  • int bytes_read
  • while((bytes_read from.read(buffer)) ! -1)
  • to_file.write(buffer, 0, bytes_read)

12
Remote Method Invocation (RMI)
  • Distributed systems
  • Sockets - flexible and sufficient, but require
    applications-level protocols (cumbersome and
    potentially error-prone)
  • Remote Procedure Call (RPC)alternative with
    illusion of calling a local procedure
  • RPC not appropriate for distributed object
    systems where remote Method Invocation (RMI) is
    better model (context of execution)
  • RMI local surrogate (stub) object manages the
    invocation of surrogate (skeleton) remote object

13
Stubs and Skeletons

client
programstubmarshallnetworknetworkunmarshall
stub returnprogram
14
Java RMI vs. CORBA
  • Java RMI integrated in the language (since JDK
    1.1)
  • Common Object Request Broker Architecture
  • OMG - Object Management Group
  • CORBA for a heterogeneous, multi-language
    environment thus a language-neutral object model
  • IDL - Interface Description Language
  • IIOP - Internet Inter-Orb Protocol
  • NDI - Naming Directory Interface
  • RMI over IIOP evolving together with CORBA

15
RMI Common Interface
  • import java.rmi.
  • public interface iCalendar extends Remote
  • java.util.Date getDate () throws
    RemoteException
  • // look at code examples

16
RMI Client
  • public class CalendarUser
  • public static void main(String args)
  • iCalendar remoteCal
  • try remoteCal (iCalendar)
  • Naming.lookup("rmi//machine/CalendarImpl")
  • t1 remoteCal.getDate().getTime()
  • t2 remoteCal.getDate().getTime()
  • catch (Exception e) e.printStackTrace()
  • System.out.println("This RMI call took "
  • (t2-t1) " milliseconds")

17
RMI Server
  • public class CalendarImpl extends
    UnicastRemoteObject implements iCalendar
  • public CalendarImpl() throws RemoteException
  • public Date getDate () throws RemoteException
  • return new Date()
  • public static void main(String args)
  • CalendarImpl cal
  • try LocateRegistry.createRegistry(1099)
  • cal new CalendarImpl()
  • Naming.bind("rmi///CalendarImpl", cal)
  • System.out.println("Ready for RMI's")
  • catch (Exception e) e.printStackTrace()

18
Stubs and Skeletons
  • Java automatically generates stubs and skeletons
    with rmic based on common interface and
    implementation .class file

client
programstubmarshallnetworknetworkunmarshall
stub returnprogram
19
Pulling it together
  • Compile client and serve
  • Generating stubs skeletons
  • Remote Method Invocation Compiler (rmic)
  • Start server
  • Run client

20
Callbacks, CORBA, J2EE
  • X11 Windows
  • reversed traditional role of client and server
  • routines on display terminal were called back
    by computer
  • terminal sent information about these routines to
    the server
  • RMI Registry is only one way of objects knowing
    each other
  • CORBA Common Object-oriented Request Broker
    Architecture
  • Microsoft COM, COM, DCOM
  • Java 2 Enterprise Edition (Enterprise Java Beans)

21
Programming Language Implications
  • Programming language constructs for distributed
    computing (like looping, testing, subprogram
    definition and calling)
  • Event driven style (program set up and waiting
    for event or request)
  • Passing by reference and value still issues
  • Programming with interfaces (interface
    inheritance v. implementation inheritance)
  • More environmental aids for programming, reusable
    classes and frameworks
Write a Comment
User Comments (0)
About PowerShow.com