1 / 16

Java Socket Programming and Java RMI CS 15-440

Java Socket Programming and Java RMI CS 15-440. Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud. Today…. Announcements All programs run on Unix cluster Use any editor/file-transfer you want Project 1 Java Socket Programming Java RMI. Project 1. Learning objective:

mascarenas
Télécharger la présentation

Java Socket Programming and Java RMI CS 15-440

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Today… • Announcements • All programs run on Unix cluster • Use any editor/file-transfer you want • Project 1 • Java Socket Programming • Java RMI

  3. Project 1 • Learning objective: • Apply the knowledge of Process and Communication and Naming to design a Distributed File System. • Duration: 3 weeks • Solo project

  4. 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

  5. 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

  6. 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

  7. Design/Implementation hints • Remote Method Invocation (RMI) heavy • We have an excellent start-up code • Read “Design guidelines” and “Implementation hints” • Come back to us • Earlier the better

  8. Java Socket Programming • Sockets: • An API for using underlying networks • An abstraction like “File” • Request-response

  9. Java Socket Programming • IP Address • To name a machine/host • Port • Port maps to one connection-end-point • For your apps: Use ports 49152 through 65535 • Types of Sockets • UDP (Datagram) vs TCP (Conn-oriented)

  10. java.net class • A package that provide base classes and API for Socket programming • Open/close socket • Accept • Read/Write • Send/Receive

  11. TCP Sockets • Classes • java.net.ServerSocket, java.net.Socket • DataInputStream, DataOutputStream

  12. TCP Socket • Server • Client ServerSocket server = new ServerSocket( PORT ); Socket client = server.accept(); DataInputStream is = new DataInputStream(client.getInputStream()); DataOutputStreamos = new DataOutputStream(client.getOutputStream()); String line = is.readLine(); os.writeBytes(“Hello\n”); client.close(); Socket client = new Socket(server, port_id); DIS/DOS  Same as in server Read/Write  Same as in server Close  Same as in server

  13. 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

  14. Java RMI • What is RMI? • What do we need • Where is the server? • Which object/method should I call? • What if I do not know the server object definition? • How to communicate?

  15. Java RMI • How do we implement? • Look-up for server/object • RMI Registry • Remote interface • Extend Remote interface • Throw RemoteException • Make it accessible • How does the magic happen? • Stub/Skeleton, Serialize

  16. References • http://www.buyya.com/java/Chapter13.pdf • http://www.generalsoftwares.co.uk/remote-services.html

More Related