networkable solutions

6
Duke CPS 108 18.1 Networkable solutions Using sockets we can pass objects back and forth between client and server, but we’re limited Cannot call methods on objects between client/server, only send objects and respond to protocols Conceivably we’ll run into firewall problems RMI, Remote Method Invocation, can fix both these problems Clients call methods across machines, on objects running in other JVMs Built on top of HTTP, so can (in theory) be used through firewalls Different in 1.1/1.2, requires a fair amount of bookkeeping overhead to set up

Upload: kaia

Post on 09-Jan-2016

16 views

Category:

Documents


0 download

DESCRIPTION

Networkable solutions. Using sockets we can pass objects back and forth between client and server, but we’re limited Cannot call methods on objects between client/server, only send objects and respond to protocols Conceivably we’ll run into firewall problems - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Networkable solutions

Duke CPS 108 18.1

Networkable solutions

Using sockets we can pass objects back and forth between client and server, but we’re limited Cannot call methods on objects between

client/server, only send objects and respond to protocols

Conceivably we’ll run into firewall problems

RMI, Remote Method Invocation, can fix both these problems Clients call methods across machines, on objects

running in other JVMs Built on top of HTTP, so can (in theory) be used

through firewalls Different in 1.1/1.2, requires a fair amount of

bookkeeping overhead to set up

Page 2: Networkable solutions

Duke CPS 108 18.2

Object streams, passing objects

ObjectInputStream and ObjectOutputStream provide mechanisms for passing objects between clients Wrap streams around/in other streams, e.g., socket

streams via stream decorator pattern Send copies of objects, different from standard Java

object model where everything is a reference Objects sent must implement Serializable interface

Flag interface, no methods All fields (object graph) written, objects not written

more than once, references used for already-written objects

Possible to customize how objects are serialized using writeObject/readObject or Externalizable interface

Fields labeled as transient are not written

Page 3: Networkable solutions

Duke CPS 108 18.3

RMI ideas Think of clients and servers, though this distinction is

blurred In jdk 1.2, server-side objects can call client object

methods, so really distributed computing Still, an initial server/rmiregistry begins the RMI

process

JVMs on different machines execute, objects communicate with each other between JVMs Sockets used underneath, either TCP/IP or HTTP or

… customizable e.g., SSL

Classes can either be located in all JVMs, or transferred/downloaded using HTTP codebase Codebase is also used in applets, but restricted to

original web page as root

Page 4: Networkable solutions

Duke CPS 108 18.4

Applet codebase

JVM executing in browser has different capabilities than “regular” JVM Looks in codebase as its CLASSPATH, also uses

client/browser side CLASSPATH Codebase is relative to location of web page

originating the applet for security reasons Implications for downloading swing.jar?

Page 5: Networkable solutions

Duke CPS 108 18.5

RMI information/basics

http://java.sun.com/products/1.2/docs/guide/rmi/codebase.html

http://java.sun.com/docs/books/tutorial/rmi/

Page 6: Networkable solutions

Duke CPS 108 18.6

Downloading code in RMI