! "# $%&'( ) * ).) "%&' 1* ( %&' ! "%&'2 (! ""$ 1! ""3($



Similar documents
When the transport layer tries to establish a connection with the server, it is blocked by the firewall. When this happens, the RMI transport layer

ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty("java.security.policy","../server.java.

Programmation RMI Sécurisée

Network Communication

Remote Method Invocation

Lecture 7: Java RMI. CS178: Programming Parallel and Distributed Systems. February 14, 2001 Steven P. Reiss

Remote Method Invocation in JAVA

C:\Documents and Settings\Gijs\Desktop\src\client\Client.java dinsdag 3 november :50

Socket Programming in Java

Remote Method Invocation (RMI)

Java Network. Slides prepared by : Farzana Rahman

Communicating with a Barco projector over network. Technical note

Remote Method Invocation

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

NETWORK PROGRAMMING IN JAVA USING SOCKETS

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

The Java Series Introduction to Java RMI and CORBA. The Java Series. Java RMI and CORBA Raul RAMOS / CERN-IT User Support Slide 1

DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

Division of Informatics, University of Edinburgh

Cours. Client/serveur avancé en Java (servlets, RMI, etc.) M.M.F.A.I. François Bourdoncle

Remote Method Invocation

Network/Socket Programming in Java. Rajkumar Buyya

CS 1302 Ch 19, Binary I/O

Application Development with TCP/IP. Brian S. Mitchell Drexel University

Assignment 4 Solutions

Lesson: All About Sockets

INPUT AND OUTPUT STREAMS

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).

Report of the case study in Sistemi Distribuiti A simple Java RMI application

Creating a Simple, Multithreaded Chat System with Java

RMI Client Application Programming Interface

Mail User Agent Project

Building a Multi-Threaded Web Server

Java Programming: Sockets in Java

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

Overview of Web Services API

An Overview of Java. overview-1

An Android-based Instant Message Application

!"# $ %!&' # &! ())*!$

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets

WRITING DATA TO A BINARY FILE

Java Remote Method Invocation Specification

Decorator Pattern [GoF]

JAVA - FILES AND I/O

Client-Server Programming in Java-RMI

AVRO - SERIALIZATION

Socket-based Network Communication in J2SE and J2ME

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

RPC over XML. Web services with Java. How to install it? Reference implementation. Setting the environment variables. Preparing the system

Introduction to Java Distributed Objects - Using RMI and CORBA

Manual. Programmer's Guide for Java API

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

EJB 3.0 and IIOP.NET. Table of contents. Stefan Jäger / stefanjaeger@bluewin.ch

H2O A Lightweight Approach to Grid Computing

Introduction to Object-Oriented Programming

Jini an Infrastructure for Dynamic Service Networks

OBJECT ORIENTED PROGRAMMING LANGUAGE

Socket Programming. A er learning the contents of this chapter, the reader will be able to:

CISC 4700 L01 Network & Client- Server Programming Spring Harold, Chapter 8: Sockets for Clients

Tuple spaces and Object spaces. Distributed Object Systems 12. Tuple spaces and Object spaces. Communication. Tuple space. Mechanisms 2.

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

Chapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved.

16.1 DataFlavor DataFlavor Methods. Variables

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

CS506 Web Design and Development Solved Online Quiz No. 01

Java Programming Unit 10. Stock Price Quotes with URL, Sockets, and RMI

BEAWebLogic Server. Programming WebLogic RMI

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from

Threads & Tasks: Executor Framework

public static void main(string[] args) { System.out.println("hello, world"); } }

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.

Network Programming using sockets

Chapter 2 Introduction to Java programming

Building a Java chat server

WSDL Example (Interface) WSDL Example (Implementation) Universal Description, Discovery and Integration. UDDI Usage

Advanced Network Programming Lab using Java. Angelos Stavrou

Socket Programming. Announcement. Lectures moved to

Distributed Embedded Systems

Capario B2B EDI Transaction Connection. Technical Specification for B2B Clients

::. Contenuti della lezione *+ ') $ &,!!!$!-,.../- ' % + &

Lecture J - Exceptions

How To Write A Mapreduce Program In Java.Io (Orchestra)

Brekeke PBX Web Service

Today s Outline. Computer Communications. Java Communications uses Streams. Wrapping Streams. Stream Conventions 2/13/2016 CSE 132

Consuming a Web Service(SOAP and RESTful) in Java. Cheat Sheet For Consuming Services in Java

Java E-Commerce Martin Cooke,

Design of Cloud based Instant Messaging System on Android Smartphone using Internet

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

D06 PROGRAMMING with JAVA

Tutorial Reference Manual. Java WireFusion 4.1

Transcription:

! "# $%&'( ) * +,'-( ).) /"0'" 1 %&' 1* ( %&' "%&'! "%&'2 (! ""$ 1! ""3($ 2 ', '%&' 2

, 3, 4( 4 %&'( 2(! ""$ -5%&'* -2%&'(* ) * %&' 2! ""$ -*! " 4

, - %&' 3( #5! " 5, '56! "* * 4(%&'(! ""$ 3(#! " 42/7'89.:&! " %&',00, 0 9089;<=> 6

-! "%"-? $ %&' +, "/7'2 %&'6 $ 1 +5) ' 5 7 @7 / 1 6.* 2 -.:& # 2 6 " * A * %&' 8

@7 / 4B 2 4 2 C(D 2 * CD '@7/ # 2)#( / 5 281 #5 2* 6 9 @7 / ' C D $ 2 * #2 5 ' * E 8 : 4* * F G 10

@7/ /! & 8 - & 8'! ' 4 2 / # 2 # 11 @7/3-25 2 8C:D @7/ java Xmx512m -Djava.rmi.dgc.leaseValue=10000 RMIServer 2 E :* 12

@7/3,! import java.rmi.*; public interface Hello extends java.rmi.remote String sayhello() throws RemoteException; MessageObject getmessageobject() throws RemoteException; 13 @7/3,! ' import java.rmi.*; import java.rmi.server.*; public class HelloImpl extends UnicastRemoteObject implements Hello, Unreferenced public HelloImpl() throws RemoteException super(); public String sayhello() throws RemoteException return "Hello!"; public MessageObject getmessageobject() throws RemoteException return new MessageObjectImpl(); [to be continued ] 14

@7/3,! ' public void unreferenced() System.out.println( "HelloImpl: Unreferenced" ); public void finalize() throws Throwable super.finalize(); System.out.println( "HelloImpl: Finalize called" ); // class HelloImpl 15 @7/3,& 8 import java.io.*; import java.rmi.server.*; public interface MessageObject extends java.rmi.remote int getnumberfromobject() throws java.rmi.remoteexception; int getnumberfromclass() throws java.rmi.remoteexception; 16

@7/3,& 8' public class MessageObjectImpl extends UnicastRemoteObject implements MessageObject, Unreferenced static int number = 0; static int totalnumber = 0; private int objnumber; public MessageObjectImpl() throws RemoteException objnumber = ++number; totalnumber++; System.out.println( "MessageObject: Class Number is #" + totalnumber + " Object Number is #" + objnumber ); public int getnumberfromobject() return objnumber; [to be continued ] 17 @7/3,& 8' public int getnumberfromclass() return totalnumber; public void finalize() throws Throwable super.finalize(); totalnumber--; System.out.println( "MessageObject: Finalize for object #: " + objnumber ); public void unreferenced() System.out.println( "MessageObject: Unreferenced for object #: " + objnumber ); // class MessageObjectImpl 18

@7/3,%&'$ import java.net.*; import java.io.*; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.locateregistry; public class RMIServer private static final int PORT = 10007; private static final String HOST_NAME = " "; private static RMIServer rmi; public static void main ( String[] args ) try rmi = new RMIServer(); [to be continued ] 19 @7/3,%&'$ catch ( java.rmi.unknownhostexception uhe ) System.out.println( "The host computer name you have specified, " + HOST_NAME + " does not match your real computer name." ); catch ( RemoteException re ) System.out.println( "Error starting service" ); System.out.println( "" + re ); catch ( MalformedURLException murle ) System.out.println( "Internal error" + murle ); catch ( NotBoundException nbe ) System.out.println( "Not Bound" ); System.out.println( "" + nbe ); // main [to be continued ] 20

@7/3,%&'$ public RMIServer() throws RemoteException, MalformedURLException, NotBoundException LocateRegistry.createRegistry( PORT ); System.out.println( "Registry created on host computer" + HOST_NAME + " on port " + Integer.toString(PORT) ); Hello hello = new HelloImpl(); System.out.println( "Remote Hello service implementation object created" ); String urlstring = "//" + HOST_NAME + ":" + PORT + "/" + "Hello"; Naming.rebind( urlstring, hello ); System.out.println( "Bindings Finished, waiting for client requests." ); // class RMIServer 21 @7/3,%&'/ import java.util.date; import java.net.malformedurlexception; import java.rmi.*; public class RMIClient private static final int PORT = 10007; private static final String HOST_NAME = "name"; private static RMIClient rmi; public static void main ( String[] args ) rmi = new RMIClient(); public RMIClient() try Hello hello = (Hello)Naming.lookup( "//" + HOST_NAME + ":" + PORT + "/" + "Hello" ); [to be continued ] 22

@7/3,%&'/ System.out.println( "HelloService lookup successful" ); System.out.println( "Message from Server: " + hello.sayhello() ); MessageObject mo; for ( int i = 0; i< 1000; i++ ) mo = hello.getmessageobject(); System.out.println( "MessageObject: Class Number is #" + mo.getnumberfromclass() + " Object Number is #" + mo.getnumberfromobject() ); mo = null; Thread.sleep(500); catch ( Exception e)system.out.println(e); // class RMIClient 23 $)( - $) 2 $) '%&'/$)( $) / ) 2 '%&'$$)( $$) $)$ # $$)# /)< # 24

%&'/$)( 12 %&'/$)(* %&' ) 1 52 38 81%8 8G# 12 %&'/$)(E 25 %&'/$)( 12 88 8# 2 E #)( '8/# 12 %&'/$)(5 ( ) ( 26

%&'$$)( 12 %&'$$)( * $$) 12 %&'$$)(5 ( ) ( 27 /%&'$)( -22%&') (, /$%&' ) -) ".& H$@IFH 8%&'$)( %&' + )(.:& 28

/%&'$)(, Per questo esempio, la nostra RMI socket factory creerà socket che useranno la crittografia XOR I(,11101101 I(,11101101 @(# J 10011011 G K%# @, 01110110 G K%# @(# J 10011011 29,/%&'$)( 4 E JJL ')K% ) 30

XorInputStream import java.io.*; public class XorInputStream extends FilterInputStream private final byte pattern; public XorInputStream(InputStream in, byte pattern) super(in); this.pattern = pattern; public int read() throws IOException int b = in.read(); if (b!= -1) b = (b ^ pattern) & 0xFF; return b; [to be continued ] 31 XorInputStream public int read(byte b[], int off, int len) throws IOException int numbytes = in.read(b, off, len); if (numbytes <= 0) return numbytes; for(int i = 0; i < numbytes; i++) b[off + i] = (byte)((b[off + i] ^ pattern)& 0xFF); return numbytes; // class XorInputStream 32

XorOutputStream import java.io.*; public class XorOutputStream extends FilterOutputStream private final byte pattern; public XorOutputStream(OutputStream out, byte pattern) super(out); this.pattern = pattern; public void write(int b) throws IOException out.write((b ^ pattern) & 0xFF); 33 XorServerSocket import java.io.*; import java.net.*; public class XorServerSocket extends ServerSocket private final byte pattern; public XorServerSocket(int port, byte pattern) throws IOException super(port); this.pattern = pattern; public Socket accept() throws IOException Socket s = new XorSocket(pattern); implaccept(s); return s; 34

XorSocket import java.io.*; import java.net.*; public class XorSocket extends Socket private final byte pattern; private InputStream in = null; private OutputStream out = null; public XorSocket(byte pattern) throws IOException super(); this.pattern = pattern; public XorSocket(String host, int port, byte pattern) throws IOException super(host, port); this.pattern = pattern; [to be continued ] 35 XorSocket public synchronized InputStream getinputstream() throws IOException if (in == null) in = new XorInputStream(super.getInputStream(), pattern); return in; public synchronized OutputStream getoutputstream() throws IOException if (out == null) out = new XorOutputStream(super.getOutputStream(), pattern); return out; // class XorSocket 36

XorClientSocketFactory import java.io.*; import java.net.*; import java.rmi.server.*; public class XorClientSocketFactory implements RMIClientSocketFactory, Serializable private final byte pattern; public XorClientSocketFactory(byte pattern) this.pattern = pattern; public Socket createsocket(string host, int port) throws IOException return new XorSocket(host, port, pattern); [to be continued ] 37 XorClientSocketFactory public int hashcode() return (int) pattern; public boolean equals(object obj) return (getclass() == obj.getclass() && pattern == ((XorClientSocketFactory) obj).pattern); //class XorClientSocketFactory 38

XorServerSocketFactory import java.io.*; import java.net.*; import java.rmi.server.*; public class XorServerSocketFactory implements RMIServerSocketFactory private byte pattern; public XorServerSocketFactory(byte pattern) this.pattern = pattern; public ServerSocket createserversocket(int port) throws IOException return new XorServerSocket(port, pattern); public int hashcode() [Same as client] public boolean equals(object obj) [Same as client] 39 interface Hello e HelloImpl public interface Hello extends java.rmi.remote String sayhello() throws java.rmi.remoteexception; import java.io.*; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; public class HelloImpl implements Hello public HelloImpl() public String sayhello() return "Hello World!"; public static void main(string args[]) System.setSecurityManager(new SecurityManager()); [to be continued ] 40

HelloImpl byte pattern = (byte) 0xAC; try HelloImpl obj = new HelloImpl(); RMIClientSocketFactory csf = new XorClientSocketFactory(pattern); RMIServerSocketFactory ssf = new XorServerSocketFactory(pattern); Hello stub = (Hello) UnicastRemoteObject. exportobject(obj, 0, csf, ssf); LocateRegistry.createRegistry(2002); Registry registry = LocateRegistry.getRegistry(2002); registry.rebind("hello", stub); System.out.println("HelloImpl bound in registry"); catch (Exception e) //class HelloImpl 41 HelloClient import java.rmi.*; import java.rmi.registry.*; public class HelloClient public static void main(string args[]) System.setSecurityManager(new SecurityManager()); try Registry registry = LocateRegistry.getRegistry(2002); Hello obj = (Hello) registry.lookup("hello"); String message = obj.sayhello(); System.out.println(message); catch (Exception e) System.out.println("HelloClient exception: " + e.getmessage()); e.printstacktrace(); 42

$$- $ $)-( -$-( $(.$$. $ $)3! "##$ # % " 43 %&'$$- %&'$$- 44