Java Technologies. Lecture VII. Valdas Rapševičius. Vilnius University Faculty of Mathematics and Informatics

Size: px
Start display at page:

Download "Java Technologies. Lecture VII. Valdas Rapševičius. Vilnius University Faculty of Mathematics and Informatics"

Transcription

1 Preparation of the material was supported by the project Increasing Internationality in Study Programs of the Department of Computer Science II, project number VP1 2.2 ŠMM-07-K , funded by The European Social Fund Agency and the Government of Lithuania. Java Technologies Lecture VII Valdas Rapševičius Vilnius University Faculty of Mathematics and Informatics

2 Session Outline You will learn networking basics in Java, namely TCP Sockets Datagram Sockets Network Interfaces URL RMI Java Policy for Networking 2

3 Protocols Computers running on the Internet communicate to each other using either the Transmission Control Protocol (TCP) or the User Datagram Protocol (UDP) TCP (Transmission Control Protocol) is a connection-based protocol that provides a reliable flow of data between two computers. UDP (User Datagram Protocol) is a protocol that sends independent packets of data, called datagrams, from one computer to another with no guarantees about arrival. UDP is not connection-based like TCP. The TCP and UDP protocols use ports to map incoming data to a particular process running on a computer. 3

4 Basic networking classes in JDK java.net package TCP protocol classes URL URLConnection Socket ServerSocket SocketChannel UDP protocol classes DatagramPacket DatagramSocket MulticastSocket java.net.networkinterface class 4

5 Sockets A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent. 5

6 Socket class try (Socket socket = new Socket(HOSTNAME, PORT)) { try (PrintWriter out = new PrintWriter(socket.getOutputStream(), true) { try (Reader isr = new InputStreamReader(socket.getInputStream())) { try (BufferedReader in = new BufferedReader(isr)) { String somedata = "this is a message!"; out.println(somedata); System.out.println("return: " + in.readline()); catch (UnknownHostException e) { System.err.format("Don't know about host: %s.%n, HOSTNAME); catch (IOException e) { System.err.format("I/O problem for the connection to: %s.%n", HOSTNAME); 6

7 ServerSocket class try (ServerSocket ssocket = new ServerSocket(PORT)) { Socket socket = ssocket.accept(); OutputStream os = socket.getoutputstream(); try (PrintWriter out = new PrintWriter(os, true)) { InputStream is = csocket.getinputstream(); try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) { String line; while ((line = in.readline())!= null) { out.println("thanks for: " + line); catch (IOException e) { System.err.format("Could not listen on port: %d.%n", PORT); 7

8 DatagramSocket class A datagram is an independent, self-contained message sent over the network whose arrival, arrival time, and content are not guaranteed. byte[] buf = new byte[256]; // Binds Datagram socket to the certain port (aka Server) DatagramSocket socket = new DatagramSocket(4445); DatagramPacket packet = new DatagramPacket(buf, buf.length); socket.receive(packet); // Get client socket info from the packet InetAddress address = packet.getaddress(); int port = packet.getport(); // And send something back packet = new DatagramPacket(buf, buf.length, address, port); socket.send(packet); // Create Datagram socket on any available local port (aka Client) DatagramSocket socket = new DatagramSocket(); InetAddress serveraddr = InetAddress.getByName("localhost"); DatagramPacket packet = new DatagramPacket(buf, buf.length, serveraddr, 4445); socket.send(packet); 8

9 MulticastSocket class MulticastSocket is used on the client-side to listen for packets that the server broadcasts to multiple clients. byte[] buf = new byte[256]; // Server sends a message to the group DatagramSocket socket = new DatagramSocket(); InetAddress group = InetAddress.getByName(" "); DatagramPacket packet = new DatagramPacket(buf, buf.length, group, 4446); socket.send(packet); // Client to listen to message broadcast MulticastSocket socket = new MulticastSocket(4446); InetAddress group = InetAddress.getByName(" "); socket.joingroup(group); DatagramPacket packet = new DatagramPacket(buf, buf.length); socket.receive(packet); String received = new String(packet.getData()); System.out.println(received); socket.leavegroup(group); socket.close(); 9

10 Network Interface A network interface is the point of interconnection between a computer and a private or public network. A network interface is generally a network interface card (NIC), but does not have to have a physical form. Instead, the network interface can be implemented in software. For example, the loopback interface ( for IPv4 and ::1 for IPv6) is not a physical device but a piece of software simulating a network interface. The loopback interface is commonly used in test environments. // Create socket and connect to InetSocketAddress Socket soc = new java.net.socket(); soc.connect(new InetSocketAddress(IP, PORT)); // Get NIC addresses NetworkInterface nif = NetworkInterface.getByName("lo"); Enumeration<InetAddress> addrs = nif.getinetaddresses(); InetAddress addr = addrs.nextelement(); // Bind to existing NIC address InetSocketAddress sockaddr = new InetSocketAddress(addr, PORT); soc.bind(sockaddr); soc.connect(sockaddr); 10

11 NetworkInterface class Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface net : Collections.list(nets)) { out.printf("display name: %s\n", net.getdisplayname()); out.printf("name: %s\n", net.getname()); Enumeration<NetworkInterface> subnets = net.getsubinterfaces(); for (NetworkInterface subnet : Collections.list(subnets)) { out.printf("\tsub Interface Display name: %s\n", subnet.getdisplayname()); out.printf("\tsub Interface Name: %s\n", subnet.getname()); Enumeration<InetAddress> inetaddresses = net.getinetaddresses(); for (InetAddress inetaddress : Collections.list(inetAddresses)) { out.printf("inetaddress: %s\n", inetaddress); out.printf("up? %s\n", net.isup()); out.printf("loopback? %s\n", net.isloopback()); out.printf("pointtopoint? %s\n", net.ispointtopoint()); out.printf("supports multicast? %s\n", net.supportsmulticast()); out.printf("virtual? %s\n", net.isvirtual()); out.printf("hardware address: %s\n", Arrays.toString(net.getHardwareAddress())); out.printf("mtu: %s\n", net.getmtu()); 11

12 URI Uniform Resource Identifiers (URI) provide a simple and extensible means for identifying a resource. URIs: RFC1630, issued in June 1994, was called "Universal Resource Identifiers in WWW: A Unifying Syntax for the Expression of Names and Addresses of Objects on the Network as used in the World-Wide Web". URI consists of 2 parts: URLs: RFC1738, issued in December 1994, was called "Uniform Resource Locators. mailto:valdas.rapsevicius@mif.vu.lt jar: URNs: RFC1737, issued December 1994, was called "Functional Requirements for Uniform Resource Names. urn:isan: e o urn:uuid:6e8bc430-9c3a-11d c9a66 urn:nbn:de:bvb: urn:isbn:

13 URL class import java.net.*; import java.io.*; public class ParseURL { public static void main(string[] args) throws Exception { URL url = new URL(" + "/index.html?name=networking#downloading"); System.out.println("protocol = " + url.getprotocol()); System.out.println("authority = " + url.getauthority()); System.out.println("host = " + url.gethost()); System.out.println("port = " + url.getport()); System.out.println("path = " + url.getpath()); System.out.println("query = " + url.getquery()); System.out.println("filename = " + url.getfile()); System.out.println("ref = " + url.getref()); 13

14 URL: direct InputStream import java.net.*; import java.io.*; public class URLReader { public static void main(string[] args) throws Exception { URL mif = new URL(" BufferedReader in = new BufferedReader(new InputStreamReader(mif.openStream())); String inputline; while ((inputline = in.readline())!= null) { System.out.println(inputLine); in.close(); 14

15 URLConnection class // Create connection URL url = new URL(myUrl); // HttpURLConnection, JarURLConnection concrete classes // based on URL type URLConnection con = url.openconnection(); // Write some data connection.setdooutput(true); OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream()); out.write(mydata); out.close(); // Read data Reader reader = new InputStreamReader(con.getInputStream()); BufferedReader in = new BufferedReader(reader); String data; while ((data = in.readline())!= null) { System.out.println(data); in.close(); 15

16 The network is the computer Consider the following program organization: method call SomeClass AnotherClass returned object computer 1 computer 2 If the network is the computer, we ought to be able to put the two classes on different computers RMI is one technology that makes this possible 16

17 Roadmap to Remote Method Invocation CORBA (Common Object Request Broker Architecture) was used for a long time CORBA supports object transmission between virtually any languages Objects have to be described in IDL (Interface Definition Language), which looks a lot like C++ data definitions CORBA is complex and flaky CORBA has fallen out of favor Microsoft supported CORBA, then COM, now.net RMI is purely Java-specific Java to Java communications only As a result, RMI is much simpler than CORBA 17

18 RMI overview Java makes RMI (Remote Method Invocation) fairly easy, but there are some extra steps To send a message to a remote server object, The client object has to find the object Do this by looking it up in a registry The client object then has to marshal the parameters (prepare them for transmission) Java requires Serializable parameters The server object has to unmarshal its parameters, do its computation, and marshal its response The client object has to unmarshal the response Much of this is done for you by special software 18

19 RMI components Steps for RMI application implementation: Defining the remote interfaces. A remote interface specifies the methods that can be invoked remotely by a client. Clients program to remote interfaces, not to the implementation classes of those interfaces. The design of such interfaces includes the determination of the types of objects that will be used as the parameters and return values for these methods. If any of these interfaces or classes do not yet exist, you need to define them as well. Implementing the remote objects. Remote objects must implement one or more remote interfaces. The remote object class may include implementations of other interfaces and methods that are available only locally. If any local classes are to be used for parameters or return values of any of these methods, they must be implemented as well. Implementing the clients. Clients that use remote objects can be implemented at any time after the remote interfaces are defined, including after the remote objects have been deployed. 19

20 RMI: Remote interface An object becomes remote by implementing a remote interface, which has the following characteristics: A remote interface extends the interface java.rmi.remote. Each method of the interface declares java.rmi.remoteexception in its throws clause, in addition to any application-specific exceptions. package lt.vu.mif.javatech.rmi.remote; import java.rmi.remote; import java.rmi.remoteexception; public interface Calc extends Remote { public int add(int i,int j) throws RemoteException; 20

21 RMI: server implementation package lt.vu.mif.javatech.rmi.server; import java.rmi.*; import lt.vu.mif.javatech.rmi.remote.calc; public class CalcImpl implements Calc { public int add(int i,int j)throws RemoteException { return i + j; public static void main(string[] args) { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); try { CalcImpl c = new CalcImpl(); CalcImpl stub = (CalcImpl) UnicastRemoteObject.exportObject(c, 0); Registry registry = LocateRegistry.getRegistry(); registry.rebind("calc", stub); catch (Exception e) { e.printstacktrace(); 21

22 RMI: client implementation package lt.vu.mif.javatech.rmi.client; import java.rmi.registry.*; import lt.vu.mif.javatech.rmi.remote.calc; public class CalcClient { public static void main(string args[]) { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); try { Registry registry = LocateRegistry.getRegistry(args[0]); Calc calc = (Calc) registry.lookup("calc"); System.out.println(calc.add(5, 9)); catch (Exception e) { e.printstacktrace(); 22

23 RMI: running example Policy files Server and client applications have to have policy files defined to grant permissions to execute the code on/from remote machine. I.e. grant codebase "file:/path/to/class/files/" { permission java.security.allpermission; ; Start RMI registry The RMI registry is a simple server-side bootstrap naming facility that enables remote clients to obtain a reference to an initial remote object. By default, the registry runs on port rmiregistry & Start server application java -cp rmi_server.jar -Djava.rmi.server.hostname= Djava.security.policy=server.policy lt.vu.mif.javatech.rmi.server.calcimpl Execute client application java -cp rmi_client.jar -Djava.security.policy=client.policy lt.vu.mif.javatech.rmi.client.calcclient

24 Java Policy File In Java 2, the java application must first obtain information regarding its privileges. It can obtain the security policy through a policy file. In above example, we allow Java code to have all permissions: grant { permission java.security.allpermission; ; Now, we given an example for assigning resource permissions: grant { permission java.io.filepermission "/tmp/*", "read", "write"; permission java.net.socketpermission "somehost.somedomain.com:999", "connect"; permission java.net.socketpermission "*: ", "connect,request"; permission java.net.socketpermission "*:80", "connect"; ; allow the Java code to read/write any files only under the /tmp directory, includes any subdirectories allow all java classes to establish a network connection with the host somehost.somedomain.com on port 999 allows classes to connection to or accept connections on unprivileged ports greater than 1024, on any host allows all classes to connect to the HTTP port 80 on any host. 24

25 Session Conclusions You must be able to program application layer on top of Java provided transport layer tools You now understand the Java RMI protocol and basic usage. Start from there! 25

Networking Basics. network communication.

Networking Basics. network communication. JAVA NETWORKING API Networking Basics When you write Java programs that communicate over the network, you are programming at the application layer. Typically, you don't need to concern yourself with the

More information

Network Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Network Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff Network Programming by Vlad Costel Ungureanu for Learn Stuff Java Network Protocols 2 Java Network Protocols 3 Addresses Innet4Address (32-bit) 85.122.23.145 - numeric pentalog.com symbolic Innet6Address

More information

Java Networking (sockets)

Java Networking (sockets) Java Networking (sockets) Rui Moreira Links: http://java.sun.com/docs/books/tutorial/networking/toc.html#sockets http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets_p.html Networking Computers

More information

Network Programming Benoît Garbinato

Network Programming Benoît Garbinato Network Programming Benoît Garbinato 1 Network programming Network programming is not distributed programming (somewhat lower-level) They both rely on: computers as processing & storage resources a network

More information

Advanced Java Programming. Networking

Advanced Java Programming. Networking Advanced Java Programming Networking Eran Werner and Ohad Barzilay Tel-Aviv University Advanced Java Programming, Spring 2006 1 Overview of networking Advanced Java Programming, Spring 2006 2 TCP/IP protocol

More information

Generic architecture

Generic architecture Java-RMI Lab Outline Let first builds a simple home-made framework This is useful to understand the main issues We see later how java-rmi works and how it solves the same issues Generic architecture object

More information

Lesson: Programmatic Access to Network Parameters

Lesson: Programmatic Access to Network Parameters Lesson: Programmatic Access to Network Parameters Systems often run with multiple active network connections, such as wired Ethernet, 802.11 b/g (wireless), and bluetooth. Some applications might need

More information

RMI. Remote Method Invocation. 16-Dec-16

RMI. Remote Method Invocation. 16-Dec-16 RMI Remote Method Invocation 16-Dec-16 The network is the computer Consider the following program organization: method SomeClass call AnotherClass returned object computer 1 computer 2 If the network is

More information

Written by: Dave Matuszek

Written by: Dave Matuszek RMI Remote Method Invocation Written by: Dave Matuszek appeared originally at: http://www.cis.upenn.edu/~matuszek/cit597-2003/ 28-May-07 The network is the computer * Consider the following program organization:

More information

Lecture 3: Socket Programming

Lecture 3: Socket Programming Lecture 3: Socket Programming Prof. Shervin Shirmohammadi SITE, University of Ottawa Fall 2005 CEG4183/ELG4183 3-1 Sockets From a logical perspective, a Socket is a communication end point. It is not a

More information

Java Programming Language Advance Feature

Java Programming Language Advance Feature Java Programming Language Advance Feature Peter.Cheng founder_chen@yahoo.com.cn http://www.huihoo.com 2004-04 Huihoo - Enterprise Open Source http://www.huihoo.com 1 Course Goal The main goal of this course

More information

C18: Network Fundamentals and Reliable Sockets

C18: Network Fundamentals and Reliable Sockets CISC 3120 C18: Network Fundamentals and Reliable Sockets Hui Chen Department of Computer & Information Science CUNY Brooklyn College 4/16/2018 CUNY Brooklyn College 1 Outline Networking fundamentals Network

More information

Remote Method Invocation

Remote Method Invocation Remote Method Invocation A true distributed computing application interface for Java, written to provide easy access to objects existing on remote virtual machines Provide access to objects existing on

More information

presentation DAD Distributed Applications Development Cristian Toma

presentation DAD Distributed Applications Development Cristian Toma Lecture 8 S4 - Core Distributed Middleware Programming in JEE presentation DAD Distributed Applications Development Cristian Toma D.I.C.E/D.E.I.C Department of Economic Informatics & Cybernetics www.dice.ase.ro

More information

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark Network Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark jbb@ase.au.dk Outline Socket programming If we have the time: Remote method invocation (RMI) 2 Socket Programming Sockets

More information

Java.net Package and Classes(Url, UrlConnection, HttpUrlConnection)

Java.net Package and Classes(Url, UrlConnection, HttpUrlConnection) Java.net Package and Classes(Url, UrlConnection, HttpUrlConnection) Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in

More information

Java Socket Workshop. July Purpose of this workshop:

Java Socket Workshop. July Purpose of this workshop: Java Socket Workshop July 2012 Purpose of this workshop: The objective of this workshop is to gain experience with writing and compiling programs using the Java programming language. The exercises provide

More information

Lecture 3. Java Socket Programming. TCP, UDP and URL

Lecture 3. Java Socket Programming. TCP, UDP and URL Lecture 3 TCP, UDP and URL 1 Java Sockets Programming The package java.net provides support for sockets programming (and more). Typically you import everything defined in this package with: import java.net.*;

More information

RMI. (Remote Method Invocation)

RMI. (Remote Method Invocation) RMI (Remote Method Invocation) Topics What is RMI? Why RMI? Architectural components Serialization & Marshaled Objects Dynamic class loading Code movement Codebase ClassLoader delegation RMI Security Writing

More information

IBD Intergiciels et Bases de Données

IBD Intergiciels et Bases de Données IBD Intergiciels et Bases de Données RMI-based distributed systems Fabien Gaud, Fabien.Gaud@inrialpes.fr Overview of lectures and practical work Lectures Introduction to distributed systems and middleware

More information

Object Interaction. Object Interaction. Introduction. Object Interaction vs. RPCs (2)

Object Interaction. Object Interaction. Introduction. Object Interaction vs. RPCs (2) Introduction Objective To support interoperability and portability of distributed OO applications by provision of enabling technology Object interaction vs RPC Java Remote Method Invocation (RMI) RMI Registry

More information

Principles, Models and Applications for Distributed Systems M

Principles, Models and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models and Applications for Distributed Systems M Lab assignment 2 (worked-out) Connectionless Java Sockets Luca Foschini 2010/2011 Exercise

More information

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4 EEC-681/781 Distributed Computing Systems Lecture 4 Department of Electrical and Computer Engineering Cleveland State University wenbing@ieee.org Outline Inter-process communications Computer networks

More information

Chapter 15: Distributed Communication. Sockets Remote Procedure Calls (RPCs) Remote Method Invocation (RMI) CORBA Object Registration

Chapter 15: Distributed Communication. Sockets Remote Procedure Calls (RPCs) Remote Method Invocation (RMI) CORBA Object Registration Chapter 15: Distributed Communication Sockets Remote Procedure Calls (RPCs) Remote Method Invocation (RMI) CORBA Object Registration Sockets Defined as an endpoint for communcation Concatenation of IP

More information

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming Spring 2018 CSCD 330 Network Programming Spring 2018 Lecture 6 Application Layer Socket Programming in Java Reading for Java Client/Server see Relevant Links Some Material in these slides from J.F Kurose and K.W.

More information

Introduction to Sockets 9/25/14

Introduction to Sockets 9/25/14 Introduction to Sockets 9/25/14 81 Remote communication Inter-process communication is at the heart of all distributed systems Using the network protocol stack on a node is the only way to communicate

More information

C19: User Datagram and Multicast

C19: User Datagram and Multicast CISC 3120 C19: User Datagram and Multicast Hui Chen Department of Computer & Information Science CUNY Brooklyn College 4/18/2018 CUNY Brooklyn College 1 Outline Recap Network fundamentals IPv4, IPv6 addresses

More information

55:182/22C:182. Distributed Application Frameworks Java RMI, CORBA, Web Services (SOAP)

55:182/22C:182. Distributed Application Frameworks Java RMI, CORBA, Web Services (SOAP) 55:182/22C:182 Distributed Application Frameworks Java RMI, CORBA, Web Services (SOAP) Broker Architecture Example Java Remote Method Invocation (RMI) Invoking a method which lies in a different address

More information

CSCD 330 Network Programming Winter 2019

CSCD 330 Network Programming Winter 2019 CSCD 330 Network Programming Winter 2019 Lecture 7 Application Layer Socket Programming in Java Reading: Chapter 2, Java links Relevant Links page Some Material in these slides from J.F Kurose and K.W.

More information

Questions and Answers. A. RMI allows us to invoke a method of java object that executes on another machine.

Questions and Answers. A. RMI allows us to invoke a method of java object that executes on another machine. Q.1) What is Remote method invocation (RMI)? A. RMI allows us to invoke a method of java object that executes on another machine. B. RMI allows us to invoke a method of java object that executes on another

More information

Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 URL

Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 URL Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 What is a thread Why use multiple threads Issues and problems involved Java threads Natasha Alechina School of Computer

More information

Verteilte Systeme UE Important Code

Verteilte Systeme UE Important Code Verteilte Systeme UE Important Code Lab 1 Create ServerSocket ServerSocket serversocket = new ServerSocket(tcpPort); //throws IOException Accept ClientSocket Socket clientsocket = serversocket.accept();

More information

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics G52APR Application programming Networking in Java Michael Li http://www.cs.nott.ac.uk/~jwl/g52apr Outlines Networking basics Network architecture IP address and port Server-client model TCP and UDP protocol

More information

Networking and Security

Networking and Security Chapter 03 Networking and Security Mr. Nilesh Vishwasrao Patil Government Polytechnic Ahmednagar Socket Network socket is an endpoint of an interprocess communication flow across a computer network. Sockets

More information

Distributed Systems COMP 212. Lecture 8 Othon Michail

Distributed Systems COMP 212. Lecture 8 Othon Michail Distributed Systems COMP 212 Lecture 8 Othon Michail HTTP Protocol Hypertext Transfer Protocol Used to transmit resources on the WWW HTML files, image files, query results, Identified by Uniform Resource

More information

JAVA RMI. Remote Method Invocation

JAVA RMI. Remote Method Invocation 1 JAVA RMI Remote Method Invocation 2 Overview Java RMI is a mechanism that allows one to invoke a method on an object that exists in another address space. The other address space could be: On the same

More information

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION SUMMARY REMOTE METHOD INVOCATION PROGRAMMAZIONE CONCORRENTE E DISTR. Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2015 2016 rcardin@math.unipd.it Introduction

More information

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming Spring 2018 CSCD 330 Network Programming Spring 2018 Lecture 7 Application Layer Socket Programming in Java Reading: Chapter 2, Java links Relevant Links page Some Material in these slides from J.F Kurose and K.W.

More information

Unit 1 Java Networking

Unit 1 Java Networking Q1. What is Server Socket? Discuss the difference between the Socket and ServerSocket class. The ServerSocket class (java.net) can be used to create a server socket. This object is used to establish communication

More information

Distributed Objects. Remote Method Invokation

Distributed Objects. Remote Method Invokation Distributed Objects Remote Method Invokation Distributed Systems Object Oriented Paradigm invoke method Object 1 Object 2 respond Distributed Object Oriented Paradigm Client Host/Process invoke method

More information

Remote Method Invocation

Remote Method Invocation Non-101samples available here: https://github.com/101companies/101repo/tree/master/languages/aspectj/javarmisamples Remote Method Invocation Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages

More information

Java for Interfaces and Networks

Java for Interfaces and Networks Java for Interfaces and Networks Threads and Networking Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces and Networks Lecture

More information

Interprocess Communication

Interprocess Communication Interprocess Communication Nicola Dragoni Embedded Systems Engineering DTU Informatics 4.2 Characteristics, Sockets, Client-Server Communication: UDP vs TCP 4.4 Group (Multicast) Communication The Characteristics

More information

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING 1 OBJECT ORIENTED PROGRAMMING Lecture 14 Networking Basics Outline 2 Networking Basics Socket IP Address DNS Client/Server Networking Class & Interface URL Demonstrating URL Networking 3 Java is practically

More information

URL Kullanımı Get URL

URL Kullanımı Get URL Networking 1 URL Kullanımı Get URL URL info 2 import java.io.*; import java.net.*; public class GetURL { public static void main(string[] args) { InputStream in = null; OutputStream out = null; // Check

More information

JAVA SOCKET PROGRAMMING

JAVA SOCKET PROGRAMMING JAVA SOCKET PROGRAMMING WHAT IS A SOCKET? Socket The combination of an IP address and a port number. (RFC 793 original TCP specification) The name of the Berkeley-derived application programming interfaces

More information

Distributed Systems Recitation 2. Tamim Jabban

Distributed Systems Recitation 2. Tamim Jabban 15-440 Distributed Systems Recitation 2 Tamim Jabban Project 1 Involves creating a Distributed File System (DFS) Released yesterday When/If done with PS1, start reading the handout Today: Socket communication!

More information

RMI Example RMI. CmpE 473 Internet Programming RMI

RMI Example RMI. CmpE 473 Internet Programming RMI CmpE 473 Internet Programming Pınar Yolum pinar.yolum@boun.edu.tr Department of Computer Engineering Boğaziçi University RMI Examples from Advanced Java: Internet Applications, Art Gittleman Remote Method

More information

Chapter 2 Applications and

Chapter 2 Applications and Chapter 2 Applications and Layered Architectures Sockets Socket API API (Application Programming Interface) Provides a standard set of functions that can be called by applications Berkeley UNIX Sockets

More information

Assignment 1. Due date February 6, 2007 at 11pm. It must be submitted using submit command.

Assignment 1. Due date February 6, 2007 at 11pm. It must be submitted using submit command. Assignment 1 Due date February 6, 2007 at 11pm. It must be submitted using submit command. Note: submit 4213 a1 . Read the manpages ("man submit") for more details on the submit command. It is

More information

Software Practice 1 - Socket

Software Practice 1 - Socket Software Practice 1 - Socket Terms of socket programming Socket Implementation (TCP, UDP) Socket with multithread Serialization Lab practice Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim T.A. Sujin

More information

Principles of Software Construction. Introduction to networks and distributed systems School of Computer Science

Principles of Software Construction. Introduction to networks and distributed systems School of Computer Science Principles of Software Construction Introduction to networks and distributed systems Josh Bloch Charlie Garrod School of Computer Science 1 Administrivia Homework 5 Best Frameworks available tonight Or

More information

31 Network Programming

31 Network Programming 31 Network Programming Network / Inter-Network OODS 1997-2000 Michael Golm Network Programming 31.218 31.1 Host Addressing: InetAddress IP addresses: DNS form: www4.informatik.uni-erlangen.de "dotted quad"

More information

Networking with java (socket programming) a brief study

Networking with java (socket programming) a brief study REVIEWS COMPUTER ENGINEERING Discovery Engineering, Volume 2, Number 7, October 2013 ISSN 2320 6675 EISSN 2320 6853 Discovery Engineering REVIEWS COMPUTER ENGINEERING discovery Engineering Networking with

More information

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming COMP 213 Advanced Object-oriented Programming Lecture 20 Network Programming Network Programming A network consists of several computers connected so that data can be sent from one to another. Network

More information

RMI (Remote Method Invocation) Over the year, there have been 3 different approaches to application development:

RMI (Remote Method Invocation) Over the year, there have been 3 different approaches to application development: RMI (Remote Method Invocation) History: Over the year, there have been 3 different approaches to application development: 1. the traditional approach. 2. the client / server approach and 3. the component-

More information

Verteilte Systeme (Distributed Systems)

Verteilte Systeme (Distributed Systems) Verteilte Systeme (Distributed Systems) Karl M. Göschka Karl.Goeschka@tuwien.ac.at http://www.infosys.tuwien.ac.at/teaching/courses/ VerteilteSysteme/ Lecture 3: Communication (Part 2) Remote Procedure

More information

Chapter 4: Processes. Process Concept. Process State

Chapter 4: Processes. Process Concept. Process State Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems 4.1 Process Concept An operating

More information

TCP connections. Fundamentals of Internet Connections Objectives. Connect to an Echo port. java.net.socket

TCP connections. Fundamentals of Internet Connections Objectives. Connect to an Echo port. java.net.socket Objectives TCP connections To understand programming of clients that connect to servers via TCP To understand the basics of programming of servers that accept TCP connections To practice programming of

More information

protocols September 15,

protocols  September 15, Contents SCI 351 4 Protocols, WWW Internet applications WWW, document technology Lennart Herlaar Original slides by Piet van Oostrum September 15, 2003 SCI351-4 1 X SCI351-4 1 X Internet applications How

More information

CPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary

CPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary CPSC 441 UDP Socket Programming Department of Computer Science University of Calgary Socket programming using UDP (vs TCP) UDP: no connection between client and server vno handshaking vsender explicitly

More information

JAVA - NETWORKING (SOCKET PROGRAMMING)

JAVA - NETWORKING (SOCKET PROGRAMMING) JAVA - NETWORKING (SOCKET PROGRAMMING) http://www.tutorialspoint.com/java/java_networking.htm Copyright tutorialspoint.com The term network programming refers to writing programs that execute across multiple

More information

Internet Protocol. Chapter 5 Protocol Layering. Juho Kim Graduate School of Information & Technology Sogang University

Internet Protocol. Chapter 5 Protocol Layering. Juho Kim Graduate School of Information & Technology Sogang University Internet Protocol Chapter 5 Protocol Layering Juho Kim Graduate School of Information & Technology Sogang University Department of of Computer Science and and Engineering, Sogang University Page 1 CAD

More information

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A Contents Java RMI G53ACC Chris Greenhalgh Java RMI overview A Java RMI example Overview Walk-through Implementation notes Argument passing File requirements RPC issues and RMI Other problems with RMI 1

More information

Communication in Distributed Systems: Sockets Programming. Operating Systems

Communication in Distributed Systems: Sockets Programming. Operating Systems Communication in Distributed Systems: Sockets Programming Operating Systems TCP/IP layers Layers Message Application Transport Internet Network interface Messages (UDP) or Streams (TCP) UDP or TCP packets

More information

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication JAVA Network API To be discussed 1 - java.net... 1 2 - Connection-Oriented vs. Connectionless Communication... 1 3 - Connectionless:... 1 4 - Networking Protocols... 2 5 - Sockets... 2 6 - Multicast Addressing...

More information

Distributed Systems. 02r. Java RMI Programming Tutorial. Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017

Distributed Systems. 02r. Java RMI Programming Tutorial. Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017 Distributed Systems 02r. Java RMI Programming Tutorial Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017 1 Java RMI RMI = Remote Method Invocation Allows a method to be invoked that resides

More information

Java for Interfaces and Networks (DT3029)

Java for Interfaces and Networks (DT3029) Java for Interfaces and Networks (DT3029) Lecture 3 Threads and Networking Federico Pecora federico.pecora@oru.se Center for Applied Autonomous Sensor Systems (AASS) Örebro University, Sweden Capiscum

More information

Distributed Programming - Sockets

Distributed Programming - Sockets Distributed Programming - Sockets Piet van Oostrum May 25, 2009 Concurrency In praktische situaties krijgen we concurrency door: Processen Threads Interrupts (alleen intern in het O.S.) Processen Onafhankelijke

More information

Chapter 2 Application Layer

Chapter 2 Application Layer Chapter 2 Application Layer A note on the use of these ppt slides: We re making these slides freely available to all (faculty, students, readers). They re in PowerPoint form so you can add, modify, and

More information

Remote Method Invocation in Java

Remote Method Invocation in Java Remote Method Invocation in Java Ajay Khatri Senior Assistant Professor,Department IT Acropolis Institute of Technology & Research ajay.acropolis@gmail.com What is RMI RMI is an API that provides a mechanism

More information

Distributed Systems. 3. Access to the Transport Layer. Werner Nutt

Distributed Systems. 3. Access to the Transport Layer. Werner Nutt Distributed Systems 3. Access to the Transport Layer Werner Nutt 1 Access to the Transport Layer Processes issue requests to the transport layer (i.e., the application takes the initiative, not the transport

More information

Reliability is an issue. You cannot afford to have any of the data lost or re-ordered.

Reliability is an issue. You cannot afford to have any of the data lost or re-ordered. Appendix C Socket Programming C.1 Socket Programming in Java C.1.1 Networking Basics Computers running on the Internet communicate to each other using the Internet Protocol (IP). Usually the Transmission

More information

Lab 1 : Java Sockets

Lab 1 : Java Sockets Lab 1 : Java Sockets 1. Goals In this lab you will work with a low-level mechanism for distributed communication. You will discover that Java sockets do not provide: - location transparency - naming transparency

More information

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01 Introduction & RMI Basics CS3524 Distributed Systems Lecture 01 Distributed Information Systems Distributed System: A collection of autonomous computers linked by a network, with software to produce an

More information

Chapter 12. Network Programming

Chapter 12. Network Programming Chapter 12 Network Programming What is in This Chapter? This chapter explains how to connect your JAVA application to a network. You will learn how to read files from over the internet as well as have

More information

Programming Mobile Devices Networking

Programming Mobile Devices Networking Programming Mobile Devices Networking University of Innsbruck WS 2009/2010 thomas.strang@sti2.at Networking in General Internet composed of millions of computers running the Internet Protocol (IP) stack

More information

JAC444 - Lecture 11. Remote Method Invocation Segment 2 - Develop RMI Application. Jordan Anastasiade Java Programming Language Course

JAC444 - Lecture 11. Remote Method Invocation Segment 2 - Develop RMI Application. Jordan Anastasiade Java Programming Language Course JAC444 - Lecture 11 Remote Method Invocation Segment 2 - Develop RMI Application 1 Remote Method Invocation In this lesson you will be learning about: Designing RMI application Developing distributed object

More information

Week 13 Lab - Exploring Connections & Remote Execution

Week 13 Lab - Exploring Connections & Remote Execution Week 13 Lab - Exploring Connections & Remote Execution COSC244 & TELE202 1 Assessment This lab is worth 0.5%. The marks are awarded for completing the programming exercise and answering the questions.

More information

Sockets and RMI. CS151 Chris Pollett Dec. 5, 2005.

Sockets and RMI. CS151 Chris Pollett Dec. 5, 2005. Sockets and RMI CS151 Chris Pollett Dec. 5, 2005. Outline Echo Server with Multiple Clients Client pull/server push Remote Method Invocation Proxy Pattern Echo Server with Multiple Clients public class

More information

A Typical RMI Application

A Typical RMI Application A Typical RMI Application Client and Server run on different machines Remote Object(s) registered in rmiregistry by Server Remote Object(s) look d up by Client When necessary, code transferred from web

More information

Networking. Lecture 25 ish? COP 3252 Summer July 11, 2017

Networking. Lecture 25 ish? COP 3252 Summer July 11, 2017 Networking Lecture 25 ish? COP 3252 Summer 2017 July 11, 2017 Open-Read/Write-Close The Unix I/O system follows a paradigm usually referred to as Open-Read/Write-Close. Before a program/process can perform

More information

Architecture of So-ware Systems RMI and Distributed Components. Mar<n Rehák

Architecture of So-ware Systems RMI and Distributed Components. Mar<n Rehák Architecture of So-ware Systems RMI and Distributed Components Mar

More information

Basic Java Network Programming. CS211 July 30 th, 2001

Basic Java Network Programming. CS211 July 30 th, 2001 Basic Java Network Programming CS211 July 30 th, 2001 The Network and OSI Model IP Header TCP Header TCP/IP: A Paradox TCP Connection Oriented and Connectionless Protocols Reliable: no loss, or duplication,

More information

Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub

Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub Lebanese University Faculty of Science I Master 1 degree Computer Science Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub Starting Network

More information

PROGRAMMAZIONE AVANZATA JAVA E C

PROGRAMMAZIONE AVANZATA JAVA E C PROGRAMMAZIONE AVANZATA JAVA E C Massimiliano Redolfi Lezione 12: networks with Java TCP vs UDP https://docs.oracle.com/javase/tutorial/networking/overview/networking.html TCP vs UDP TCP (Transmission

More information

A Typical RMI Application. Case Study

A Typical RMI Application. Case Study A Typical RMI Application Client and Server run on different machines Remote Object(s) registered in rmiregistry by Server Remote Object(s) look d up by Client When necessary, code transferred from web

More information

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University CS 555: DISTRIBUTED SYSTEMS [RMI] Frequently asked questions from the previous class survey Shrideep Pallickara Computer Science Colorado State University L21.1 L21.2 Topics covered in this lecture RMI

More information

AJP: Chapter 2 Networking: 18 marks

AJP: Chapter 2 Networking: 18 marks AJP: Chapter 2 Networking: 18 marks Syllabus 2.1 Basics Socket overview, client/server, reserved sockets, proxy servers, internet addressing. 2.2 Java & the Net The networking classes & interfaces 2.3

More information

Transport layer protocols. Lecture 15: Operating Systems and Networks Behzad Bordbar

Transport layer protocols. Lecture 15: Operating Systems and Networks Behzad Bordbar Transport layer protocols Lecture 15: Operating Systems and Networks Behzad Bordbar 78 Interprocess communication Synchronous and asynchronous comm. Message destination Reliability Ordering Client Server

More information

JAVA 프로그래밍 II. Lab #7 (Networking) TCP Java Socket. TCP vs UDP 2017 학년도 1 학기 년봄학기 5/24/2017 박경신. Client. Server

JAVA 프로그래밍 II. Lab #7 (Networking) TCP Java Socket. TCP vs UDP 2017 학년도 1 학기 년봄학기 5/24/2017 박경신. Client. Server Lab #7 (Networking) 2017 학년도 1 학기 JAVA 프로그래밍 II 기존요구사항분석 Lab #6 는 Thread, Runnable 과 SwingWorker 를이용한다양한멀티스레드기능을사용 Lab #7 는 TCP/UDP 등다양한네트워크프로그래밍기능을사용 TCP, UDP, HTTP, File Transfer 514770-1 2017 년봄학기 5/24/2017

More information

Chapter 2 Application Layer

Chapter 2 Application Layer Internet and Intranet Protocols and Applications Lecture 4: Application Layer 3: Socket Programming Spring 2006 Arthur Goldberg Computer Science Department New York University artg@cs.nyu.edu Chapter 2

More information

Communication Basics, RPC & RMI. CS403/534 Distributed Systems Erkay Savas Sabanci University

Communication Basics, RPC & RMI. CS403/534 Distributed Systems Erkay Savas Sabanci University Communication Basics, RPC & RMI CS403/534 Distributed Systems Erkay Savas Sabanci University 1 Communication Models 1. Remote Procedure Call (RPC) Client/Server application 2. Remote Method Invocation

More information

Interprocess Communication

Interprocess Communication Interprocess Communication Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Introduction Applications, services

More information

Desarrollo de Aplicaciones en Red RMI. Introduction. Considerations. Considerations. RMI architecture

Desarrollo de Aplicaciones en Red RMI. Introduction. Considerations. Considerations. RMI architecture session Desarrollo de Aplicaciones en Red José Rafael Rojano Cáceres http://www.uv.mx/rrojano RMI Remote Method Invocation Introduction Java RMI let s work calling remote methods. Underneath it works with

More information

The UNIVERSITY of EDINBURGH. SCHOOL of INFORMATICS. CS4/MSc. Distributed Systems. Björn Franke. Room 2414

The UNIVERSITY of EDINBURGH. SCHOOL of INFORMATICS. CS4/MSc. Distributed Systems. Björn Franke. Room 2414 The UNIVERSITY of EDINBURGH SCHOOL of INFORMATICS CS4/MSc Distributed Systems Björn Franke bfranke@inf.ed.ac.uk Room 2414 (Lecture 3: Remote Invocation and Distributed Objects, 28th September 2006) 1 Programming

More information

Outline of Topics. UDP Socket Java Programming. Multicast in Java. Real-time protocol (RTP) XMPP and Jingle protocols. Java I/O and New IO (NIO)

Outline of Topics. UDP Socket Java Programming. Multicast in Java. Real-time protocol (RTP) XMPP and Jingle protocols. Java I/O and New IO (NIO) Outline Outline of Topics UDP Socket Java Programming Multicast in Java Real-time protocol (RTP) XMPP and Jingle protocols Java I/O and New IO (NIO) UDP Socket Java Programming User Datagram Protocol (UDP)

More information

Input from Files. Buffered Reader

Input from Files. Buffered Reader Input from Files Buffered Reader Input from files is always text. You can convert it to ints using Integer.parseInt() We use BufferedReaders to minimize the number of reads to the file. The Buffer reads

More information

CS 5010: PDP. Lecture 11: Networks CS 5010 Fall 2017 Seattle. Adrienne Slaughter, Ph.D.

CS 5010: PDP. Lecture 11: Networks CS 5010 Fall 2017 Seattle. Adrienne Slaughter, Ph.D. Lecture 11: Networks CS 5010 Fall 2017 Seattle CS 5010: PDP Adrienne Slaughter, Ph.D. ahslaughter@northeastern.edu Northeastern University 1 Agenda Networking Northeastern University 2 INTRODUCTION Northeastern

More information

Chapter 4: Processes

Chapter 4: Processes Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems 4.1 Process Concept An operating

More information