An email program As a simple example of socket programming we can implement a program that sends email to a remote site As a simple example of socket.

Slides:



Advertisements
Similar presentations
What is RMI? Remote Method Invocation –A true distributed computing application interface for Java, written to provide easy access to objects existing.
Advertisements

Java Network Programming Vishnuvardhan.M. Dept. of Computer Science - SSBN Java Overview Object-oriented Developed with the network in mind Built-in exception.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Remote Method Invocation
Network Programming Chapter 11 Lecture 6. Networks.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Prepared By E. Musa Alyaman1 URLs, InetAddresses, and URLConnections Chapter 9.
Basic Socket Programming with Java. What is a socket?  Generally refers to a stream connecting processes running in different address spaces (across.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Advanced Java Class Network Programming. Network Protocols Overview Levels of Abstraction –HTTP protocol: spoken by Web Servers and Web Clients –TCP/IP:
CS490T Advanced Tablet Platform Applications Network Programming Evolution.
1. Introducing Java Computing  What is Java Computing?  Why Java Computing?  Enterprise Java Computing  Java and Internet Web Server.
Introduction to Remote Method Invocation (RMI)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Java Server Team 8. Overview What is a Java Server? History Architecture Advantages Disadvantages Current Technologies Conclusion.
WWW and Internet The Internet Creation of the Web Languages for document description Active web pages.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Implementing Application Protocols. Overview An application protocol facilitates communication between applications. For example, an client uses.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
EE2E1. JAVA Programming Lecture 9 Network Programming.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
Beyond DHTML So far we have seen and used: CGI programs (using Perl ) and SSI on server side Java Script, VB Script, CSS and DOM on client side. For some.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
Student Learning Environment on the World Wide Web l CGI-programming in Perl for the connection of databases over the Internet. l Web authoring using Frontpage.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
CS4273: Distributed System Technologies and Programming I Lecture 7: Java Networking.
Cli/Serv.: rmiCORBA/131 Client/Server Distributed Systems v Objectives –introduce rmi and CORBA , Semester 1, RMI and CORBA.
CS4273: Distributed System Technologies and Programming Lecture 13: Review.
Chapter 18 Networking F Client/Server Communications F Simple Client/Server Applications F Serve Multiple Clients F Create Applet Clients F Send and Retrieve.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
Java Programming: Advanced Topics 1 Networking Programming Chapter 11.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
Network Programming. These days almost all devices.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Remote Method Invocation Internet Computing Workshop Lecture 17.
WWW and HTTP King Fahd University of Petroleum & Minerals
MCA – 405 Elective –I (A) Java Programming & Technology
Remote Method Invocation
What is RMI? Remote Method Invocation
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
Lecture 9 Network Programming
Chapter 27 WWW and HTTP.
Introduction to Servlets
Chapter 40 Remote Method Invocation
Chapter 46 Remote Method Invocation
Chapter 46 Remote Method Invocation
Java Remote Method Invocation
Presentation transcript:

An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket programming we can implement a program that sends to a remote site  This is taken from Core Java, vol 2, chapter 3 servers use port number 25 which is the SMTP port servers use port number 25 which is the SMTP port  Simple mail transport protocol

A client socket to the mail server can be opened on port 25 A client socket to the mail server can be opened on port 25 SMPT uses the following protocol SMPT uses the following protocol Socket s=new Socket(“engmail.bham.ac.uk”,25); HELO sending host MAIL FROM:sender address RCPT TO: recipient address DATA mail message …. QUIT

The program uses a simple GUI to input the required information The program uses a simple GUI to input the required information The send button on the GUI calls the sendMail() method which outputs the correct protocol to the mail server The send button on the GUI calls the sendMail() method which outputs the correct protocol to the mail server Socket s=new Socket(“engmail.bham.ac.uk”,25); out=new PrintWriter(s.getOutputStream()); String hostname=InetAddress.getLocalHost().getHostName(); out.println(“HELO “ + hostname); out.println(“MAIL FROM: “ + from.getText()); etc

URL connections We have seen that to send or retrieve information to a web server, we use the HTTP protocol through a client socket attached to port 80 We have seen that to send or retrieve information to a web server, we use the HTTP protocol through a client socket attached to port 80 We can do this by using normal socket-based programming and sending the correct HTTP commands We can do this by using normal socket-based programming and sending the correct HTTP commands However, Java has specific support for the HTTP protocol through its URLConnection class However, Java has specific support for the HTTP protocol through its URLConnection class  Its very easy to retrieve a file from a web server by simply providing the file’s url as a string

This sets up an input stream from a url connection This sets up an input stream from a url connection  Can turn this into a Scanner object for text processing The URLConnection class also has additional functionality related to the HTTP protocol The URLConnection class also has additional functionality related to the HTTP protocol  Querying the server for header information  Setting request properties URL u=new URL(“ URLConnection c=u.openConnection(); InputStream in=c.getInputStream();

The following simple example program opens a web page and displays the HTML The following simple example program opens a web page and displays the HTML It also checks the server response code It also checks the server response code  404 if the page is not found  200 if the connection succeeded Uses a Scanner object to output the lines of HTML Uses a Scanner object to output the lines of HTML

public class URLGet { public static void main(String[] args) throws IOException { String urlName; if (args.length > 0) urlName = args[0]; else urlName = " URL url = new URL(urlName); URLConnection c = url.openConnection(); // Check response code HttpURLConnection httpConnection = (HttpURLConnection) c; int code =httpConnection.getResponseCode(); String message=httpConnection.getResponseMessage(); System.out.println(code + " " + message); if (code!=HttpURLConnection.HTTP_OK) return; // Read server response InputStream instream=connection.getInputStream(); Scanner in=new Scanner(instream); while (in.hasNextLine()) { String input=in.nextLine(); System.out.println(input); }

Advanced networking technologies in Java In this section we will look briefly at more advanced technologies for networking in Java without looking in detail at code In this section we will look briefly at more advanced technologies for networking in Java without looking in detail at code  Sending data to a web server  CGI and servlet technology  Inter-object communication  Remote method invocation (RMI)  CORBA

CGI and servlet technology We often need to send data back to a web server We often need to send data back to a web server  Typically we fill out an online form displayed on a web browser and click a ‘submit’ button  Older web technology uses a CGI script to process the information  CGI stands for Common Gateway Interface  Typically it is a program running on the server and written in a scripting language like Perl  The CGI script processes the data submitted and sends back a response to the client – usually a HTML page

Server CGI script Client web browser http server Form data Server starts CGI script Client displays web form Script produces reply page Reply page submit Server returns reply

CGI is well established and still widely used technology CGI is well established and still widely used technology Its major disadvantage is that each request forks a new process which can make it slow Its major disadvantage is that each request forks a new process which can make it slow  Makes sharing resources tricky Also there are some security flaws with CGI – it can be fooled into running commands on the server since it uses an interpreted scripted language Also there are some security flaws with CGI – it can be fooled into running commands on the server since it uses an interpreted scripted language

Servlets are Java classes which extend the HttpServlet class. They run inside a Servlet Container which calls methods of the servlet Servlets are Java classes which extend the HttpServlet class. They run inside a Servlet Container which calls methods of the servlet  The servlet container must be part of a compliant web server which contains the Java runtime environment  They run in the Java virtual machine inside the web server and so are portable and secure  Unlike CGI each separate request creates a new thread which is able to share resources with existing running threads

Inter-object communication Object orientation is all about objects ‘communicating’ with each other by calling each others’ methods Object orientation is all about objects ‘communicating’ with each other by calling each others’ methods  What if the objects are distributed across a network?  What if the objects are implemented in different languages? (eg Java and C++)

There are two mechanisms for inter object communication across a network There are two mechanisms for inter object communication across a network  Language independent mechanism is called CORBA  Common object request broker  A separate language neutral broker object handles all messages between the objects  Generally rather slow and complex because of its generality and ability to handle legacy code  If both objects are implemented in Java a much simpler mechanism is Remote Method Invocation (RMI)

In RMI, a client object calls a method of a server object on a different machine In RMI, a client object calls a method of a server object on a different machine  Client/server terminology only applies to the single method call Client object Server object Method call with parameters Returned data (objects)

All this seems easy but the actual behind the scenes issues are complex All this seems easy but the actual behind the scenes issues are complex  Actual inter-object communictation is done through separate stub objects which package remote method calls and parameters  The server registers its objects with a naming service  The clients finds the remote objects using a url : “rmi://servername.com/”  There are complex security issues involved also as calling a remote method locally can introduce viruses However, much of this is transparent to the programmer and RMI is relatively straighforward However, much of this is transparent to the programmer and RMI is relatively straighforward

And finally….. Network programming is a doddle in Java Network programming is a doddle in Java Sockets look like ordinary I/O streams from an application programming viewpoint Sockets look like ordinary I/O streams from an application programming viewpoint The main issues are writing multi-threaded code for multiple client applications The main issues are writing multi-threaded code for multiple client applications  In the last lab exercise, you will have the opportunity to write a multi-threading server for a network-based game!