java socket programming and java rmi cs 15-440 recitation 1, sep 8, 2011 majd f. sakr, vinay kolar,...

16
Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Post on 21-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Java Socket Programming and Java RMI

CS 15-440

Recitation 1, Sep 8, 2011

Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Page 2: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Today…

AnnouncementsAll programs run on Unix cluster

Use any editor/file-transfer you want

Project 1

Java Socket Programming

Java RMI

Page 3: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Project 1

Learning objective:Apply the knowledge of Process and Communication and Naming to design a Distributed File System.

Duration: 3 weeksSolo project

Page 4: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Project Objectives

Design a Distributed File System called File Stack using RMIs

Functions provided:

Create/Read/Write files and directories

Meta-operations: list files, size

Page 5: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Components

Storage Servers:

Stores Files

Naming Server:

Maps a file to storage server

Clients:

Contact Naming to get storage server

Carry out file operation on storage server

Page 6: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Design

Storage Server Registration

Storage Servers register to Naming on boot

Client functions

Contact naming to get a file-handle to access a file

Perform file operation

All functionalities through RMI

Stubs/Skeletons

Serialization

Page 7: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Design/Implementation hints

Page 8: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Java Socket Programming

Page 9: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Java Socket Programming

IP AddressTo name a machine/host

PortPort maps to one connection-end-point

For your apps: Use ports 49152 through 65535

Types of Sockets UDP (Datagram) vs TCP (Conn-oriented)

Page 10: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

java.net class

A package that provide base classes and API for Socket programming

Open/close socket

Accept

Read/Write

Send/Receive

Page 11: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

TCP Sockets

Page 12: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

TCP Socket

Server

Client1. Socket client = new Socket(server, port_id);2. DIS/DOS Same as in server3. Read/Write Same as in server4. Close Same as in server

1. ServerSocket server = new ServerSocket( PORT );2. Socket client = server.accept();3. DataInputStream is = new DataInputStream(client.getInputStream());4. DataOutputStream os = new DataOutputStream(client.getOutputStream());5. String line = is.readLine();6. os.writeBytes(“Hello\n”);7. client.close();

Page 13: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Exercise

Write a simple chat server and client using TCP Sockets (Estimated time: 20 mins)

Step 1:Client connects to server. Sends a message

Server sends back all the message that it has received from all clients

Step 2:One client should not block the server

Page 14: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Java RMI

What is RMI?

What do we needWhere is the server?

Which object/method should I call?

What if I do not know the server object definition?

How to communicate?

Page 15: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Java RMI

How do we implement?Look-up for server/object

RMI Registry

Remote interfaceExtend Remote interface

Throw RemoteException

Make it accessible

How does the magic happen? Stub/Skeleton, Serialize

Page 16: Java Socket Programming and Java RMI CS 15-440 Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

References

http://www.buyya.com/java/Chapter13.pdf

http://www.generalsoftwares.co.uk/remote-services.html