DOC PREVIEW
CMU ISM 95702 - Organizational Communications and Distributed Object Technologies

This preview shows page 1-2-3-23-24-25-26-47-48-49 out of 49 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

95-702 Distributed Systems Information System Management 1 Organizational Communications and Distributed Object Technologies Lecture 8 Chapter 4: Inter-process Communications95-702 Distributed Systems Information System Management 2 Middleware layers Applications, servicesMiddlewarelayersrequest-reply protocolmarshalling and external data representationUDP and TCPThischapterRMI and RPC95-702 Distributed Systems Information System Management 3 Socket and Port Abstractions message!agreed port!any port!socket!socket!Internet address = 138.37.88.249!Internet address = 138.37.94.248!other ports!client!server!95-702 Distributed Systems Information System Management 4 import java.net.*;!import java.io.*;!public class UDPClient{ ! public static void main(String args[]){ !!// args give message contents and server hostname!!DatagramSocket aSocket = null;!! try {!!!aSocket = new DatagramSocket(); !!!byte [] m = args[0].getBytes();!!!InetAddress aHost = InetAddress.getByName(args[1]);!!!int serverPort = 6789; ! ! !!!DatagramPacket request = new DatagramPacket(m, args[0].length(), aHost, serverPort);!!!aSocket.send(request); ! !! !!!byte[] buffer = new byte[1000];!!!DatagramPacket reply = new DatagramPacket(buffer, buffer.length);!!!aSocket.receive(reply);!!!System.out.println("Reply: " + new String(reply.getData()));!! }! catch (Exception e) ! {! System.out.println("Problem: " + e.toString());! }!! finally {! if(aSocket != null) aSocket.close();! }! } !}!A UDP Client95-702 Distributed Systems Information System Management 5 A UDP Server import java.net.*;!import java.io.*;!public class UDPServer {! public static void main(String args[]){ !!DatagramSocket aSocket = null;!!try{!! aSocket = new DatagramSocket(6789);!! byte[] buffer = new byte[1000];! ! while(true){! DatagramPacket request = new DatagramPacket(buffer, buffer.length);! aSocket.receive(request); ! System.out.println("Got request"); ! DatagramPacket reply = new DatagramPacket(request.getData(), request.getLength(), ! request.getAddress(), request.getPort());! aSocket.send(reply);!! }!! }! catch (Exception e){! System.out.println("Problem: " + e.getMessage());! }!! finally {! if(aSocket != null) aSocket.close();! }! }!}!Two Demonstrations 95-702 Distributed Systems Information System Management 6 1) Run the UDP client and server on the same machine. /Users/mm6/mm6/mm6/www/95-702/UDPNetworking java UDPServer java UDPClient hello localhost 2) Run a UDP client on an Android device. The server will run on a laptop. In this case, the UDP server will accept arithmetic expressions. Netbeans 6.8: Homework3Part1UDPProject/UDPServer.java Eclipse: AndroidUDPCalculatorProject Quiz: What if the client sends a packet and that packet is lost? Does this server handle concurrent visitors? Is the packet safe from eavesdropping? Could we visit this server with a .Net client?95-702 Distributed Systems Information System Management 7 TCP Client import java.net.*; import java.io.*; public class TCPClient { public static void main (String args[]) { // arguments supply message and hostname of destination Socket s = null; try{ int serverPort = 7896; s = new Socket(args[1], serverPort); DataInputStream in = new DataInputStream( s.getInputStream()); DataOutputStream out = new DataOutputStream( s.getOutputStream()); out.writeUTF(args[0]); // UTF is a string encoding see Sn 4.3 String data = in.readUTF(); System.out.println("Received: "+ data) ; } catch (Exception e) { System.out.println("Trouble: " + e.getMessage()); } finally { if(s!=null) try {s.close();} catch (IOException e) { System.out.println("close:"+e.getMessage()); } } } }95-702 Distributed Systems Information System Management 8 TCP Server(1) import java.net.*;!import java.io.*;! public class TCPServer {! public static void main (String args[]) {!!try {!! int serverPort = 7896; !! ServerSocket listenSocket = new ServerSocket(serverPort);!! while(true) {!!!Socket clientSocket = listenSocket.accept();! System.out.println("Got connection");!!!Connection c = new Connection(clientSocket);!! }!!} ! catch(IOException e) {! System.out.println("Listen :"+e.getMessage());! }! }!}!95-702 Distributed Systems Information System Management 9 TCP Server(2) class Connection extends Thread { DataInputStream in; DataOutputStream out; Socket clientSocket; public Connection (Socket aClientSocket) { try { clientSocket = aClientSocket; in = new DataInputStream( clientSocket.getInputStream()); out =new DataOutputStream( clientSocket.getOutputStream()); this.start(); } catch(IOException e) {System.out.println("Connection:"+e.getMessage());} } public void run() { try { String data = in.readUTF(); out.writeUTF("From server: " + data); } catch(Exception e) { System.out.println("EOF:"+e.getMessage()); } finally{ try {clientSocket.close();}catch (IOException e){/*close failed*/}} } }Demonstration 95-702 Distributed Systems Information System Management 10 /Users/mm6/mm6/mm6/www/95-702/TCPNetworking java TCPServer java TCPClient hello localhost95-702 Distributed Systems Information System Management 11 Quiz What if the client sends a packet and that packet is lost? Does this server handle concurrent visitors? Is the packet safe from eavesdropping? Could we visit


View Full Document

CMU ISM 95702 - Organizational Communications and Distributed Object Technologies

Documents in this Course
Homework

Homework

12 pages

Lecture

Lecture

25 pages

Lecture

Lecture

21 pages

Lecture

Lecture

24 pages

Exam

Exam

11 pages

Homework

Homework

16 pages

Homework

Homework

38 pages

lecture

lecture

38 pages

review

review

7 pages

lecture

lecture

18 pages

review

review

8 pages

Chapter2

Chapter2

32 pages

Lecture 4

Lecture 4

47 pages

Lecture

Lecture

22 pages

Naming

Naming

26 pages

lecture

lecture

34 pages

lecture

lecture

42 pages

lecture

lecture

112 pages

Lecture

Lecture

33 pages

Axis

Axis

43 pages

lecture

lecture

32 pages

review

review

17 pages

Lecture

Lecture

53 pages

Lecture

Lecture

80 pages

Lab

Lab

14 pages

Load more
Download Organizational Communications and Distributed Object Technologies
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Organizational Communications and Distributed Object Technologies and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Organizational Communications and Distributed Object Technologies 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?