Professional Documents
Culture Documents
Chapter 4
Communication (2)
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Plan
• Communication protocols
– Lower-level and higher-level
– Communication types
• Communication services
– Remote Procedure Call
– Message-oriented communication
– Multicasting
• Concrete instances
– Java sockets
– Java Remote Method Invocation (RMI)
– Java Message Service (JMS)
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Plan
• Wireshark
• Java technology
– (Java) Sockets
– Remote Procedure Call
• Java RMI
– Message-Oriented Communication
• Transient: Java sockets
• Persistent: Mickey Mouse JMS
– Multicast
• Will look at JGroups later
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Wireshark
• Great open-source tool for understanding and
debugging protocol behavior
– http://www.wireshark.org
• Features:
– Trace packets over the wire
– Sophisticated filtering language
– Display contents of each protocol
– Dump contents into file
– Display TCP conversation
Protocol decoders
for these levels
Captures frames/packets
on this level
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
A Google Client
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Berkeley and Java Sockets
new Socket()/new ServerSocket(…)
Socket.bind(…)
new ServerSocket(…)
ServerSocket.accept()
Socket.connect(…)
Socket.getOutputStream().write(...)
Socket.getInputStream().read(…)
Socket.close()
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
A Simple Client and Server
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Uses for Wireshark
• Learning about protocols
– We just saw the flow of a TCP connection
– Reverse engineer protocols
• Diagnostics
– Why does my hand-in not work…
• Hacking
– Try using Wireshark with telnet or FTP
(DO NOT USE REAL PASSWORDS!!!)
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Java Socket Hierarchy
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Java RMI
• Simple, single-language RPC system for
Java
– Stream-based transport as default mechanism
• Invoke objects on remote objects using
syntax for local invocations
– However, interfaces extend java.rmi.Remote
– And methods throw
java.rmi.RemoteException checked exception
getPatient(“Michael”)
god
getDose(“heroin”)
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
EHR.java
package ddist;
import java.rmi.*;
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Patient.java
package ddist;
import java.rmi.*;
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
PatientServer.java
package ddist;
import java.rmi.*;
import java.rmi.server.*;
Import java.util.*;
import java.rmi.*;
import java.rmi.server.*;
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
EHRServer.java (2)
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
EHRClient.java
package ddist;
import java.rmi.*;
name = ”Britney";
patient = ehr.getPatient(name);
S.o.println(name + " needs " + patient.getDose(medicine) + " unit(s) of ” + medicine);
medicine = ”amphetamine”;
S.o.println(name + " needs " + patient.getDose(medicine) + " unit(s) of ” + medicine);
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
RMI Basic Steps
• Server side
– Design and implement Remote interface
• E.g., using UnicastRemoteObject (based on TCP/IP)
– Define and implement security policy
– Use Naming.rebind to bind server object to name
• Client side
– Use Naming.lookup to find server object
– Invoke methods
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
RMI Parameter Passing
• public Patient getPatient(String name)
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
A Closer Look
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
RMI Wire Protocol (1)
• The wire format is represented by paired streams (seen from the client)
• Output Stream
– <Header> <Messages>
– <HttpMessage>
• Header
– 0x4a 0x52 0x4d 0x49 <Version> <Protocol>
• Version
– 0x00 0x01
– 0x00 0x02
• Protocol
– <StreamProtocol>
– <SingleOpProtocol>
– <MultiplexProtocol>
• StreamProtocol
– 0x4b
• Messages
– <Message>
– <Messages> <Message>
• Message
– <Call>
– <Ping>
– <DgcAck>
• Call
– 0x50 <CallData>
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
RMI Wire Protocol (2)
• The wire format is represented by paired streams (seen from the
client)
• Input Stream
– <ProtocolAck> <Returns>
– <ProtocolNotSupported>
– <HttpReturn>
• ProtocolAck
– 0x4e
• Return
– <ReturnData>
– <PingAck>
• ReturnData
– 0x51 <ReturnValue>
• PingAck
– 0x53
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Java Message Service
• A specification for a message queue
• Numerous implementations
– SUN, IBM, …
– We will see an example of using ActiveMQ which is
open source
• Communication pattern
– Loosely coupled
– Reliable
– Asynchronous
– Queue or publish/subscribe
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Summary
• We have introduced tools for distributed
programming in Java
– Protocol analyzer
• Wireshark
– Java APIs
• Sockets
• RMI
• JMS
• You will get a chance to get further
acquainted with these during exercises
and hand-ins…
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5