1 L52 Networking (1). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.

Slides:



Advertisements
Similar presentations
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Advertisements

Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
1 L54 Networking (3). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Prepared By E. Musa Alyaman1 URLs, InetAddresses, and URLConnections Chapter 9.
Socket Programming.
1 Java Networking – Part I CS , Spring 2008/9.
 Pearson Education, Inc. All rights reserved. 1 CH24 Networking : OBJECTIVES In this chapter you will learn:  To understand Java networking.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
JEditorPane Chapter 18 - Student. (c) 2005 by Elizabeth Sugar Boese JEditorPane creation Declare a JEditorPane component. JEditorPane pane; Check to see.
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
World Wide Web1 Applications World Wide Web. 2 Introduction What is hypertext model? Use of hypertext in World Wide Web (WWW) – HTML. WWW client-server.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
 Pearson Education, Inc. All rights reserved Networking.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
15-Jul-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
Networking java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
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)
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
1 Computer Communication & Networks Lecture 28 Application Layer: HTTP & WWW p Waleed Ejaz
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
E-Business William R. Mussatto CyberStrategies, Inc. 12/2/2000.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
CS 424/524: Introduction to Java Programming Lecture 25 Spring 2002 Department of Computer Science University of Alabama Joel Jones.
DBI Representation and Management of Data on the Internet.
Chapter 18 Networking F Client/Server Communications F Simple Client/Server Applications F Serve Multiple Clients F Create Applet Clients F Send and Retrieve.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
1 Streams Files are a computer’s long term memory Need ability for programs to –get information from files –copy information from program variables to.
Chapter 2 Applications and Layered Architectures Sockets.
CS 11 java track: lecture 6 This week: networking basics Sockets Vectors parsing strings.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
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.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
 2005 Pearson Education, Inc. All rights reserved Networking.
ECEN “Internet Protocols and Modeling”, Spring 2012 Course Materials: Papers, Reference Texts: Bertsekas/Gallager, Stuber, Stallings, etc Class.
Chapter 16: Networking F Client/Server Communications F Serving Multiple Clients F Applet Clients F Viewing HTML Pages F Retrieving Files from Web Servers.
Java Programming: Advanced Topics 1 Networking Programming Chapter 11.
Chapter 29 World Wide Web & Browsing World Wide Web (WWW) is a distributed hypermedia (hypertext & graphics) on-line repository of information that users.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
Socket Programming.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Distributed Systems CS Project 1: File Storage and Access Kit (FileStack) Recitation 1, Aug 29, 2013 Dania Abed Rabbou and Mohammad Hammoud.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
COMPUTER NETWORKS Hwajung Lee. Image Source:
Java’s networking capabilities are declared by the classes and interfaces of package java.net, through which Java offers stream-based communications that.
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.
WWW and HTTP King Fahd University of Petroleum & Minerals
Network Programming Introduction
MCA – 405 Elective –I (A) Java Programming & Technology
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.
Chapter 18 Networking Client/Server Communications
24 Networking.
Network Programming Introduction
Java Tutorial Zhe Li.
J2EE Lecture 1:Servlet and JSP
Presentation transcript:

1 L52 Networking (1)

2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java networking applications by using sockets and datagrams.  To understand how to implement Java clients and servers that communicate with one another.  To understand how to implement network-based collaborative applications.  To construct a multithreaded server.

Introduction Networking package is java.net – Stream-based communications Applications view networking as streams of data Connection-based protocol Uses TCP (Transmission Control Protocol – Packet-based communications Individual packets transmitted Connectionless service Uses UDP (User Datagram Protocol)

Introduction (Cont.) Client-server relationship – Client requests some action be performed – Server performs the action and responds to client – Request-response model Common implementation: Web browsers and Web servers

Manipulating URLs HyperText Transfer Protocol (HTTP) – Uses URIs (Uniform Resource Identifiers) to identify data URLs (Uniform Resource Locators) – URIs that specify the locations of documents – Refer to files, directories and complex objects HTML document SiteSelector.html (Fig. 24.1) – applet element – param tag name attribute value attribute

6 Outline Fig | HTML document to load SiteSelector applet. Declare param tags for the applet, each parameter has a name and a value SiteSelector.html Lines 5-12

7 Outline SiteSelector.java (1 of 5) Lines 3-4 Line 8 Import classes in package java.net Import interface AppletContext from package java.net

8 Outline SiteSelector.java (2 of 5) Lines Line 45 Line 48 Line 51 When the user selects one of the Web sites listed in siteChooser, the program calls method valueChanged Pass the selected site name (the key) to HashMap method get, which locates and returns a reference to the corresponding URL (the value) Get a reference to an AppletContext object that represents the applet container Display in the current browser window the resource associated with URL newDocument

9 Outline SiteSelector.java (3 of 5) Line 67 Line 73 Line 77 Lines Use Applet method getParameter to obtain a Web site title Use Applet method getParameter to obtain the Web site location Use the location as the value of a new URL object If the location passed to the URL constructor is invalid, the URL constructor throws a MalformedURLException

10 Outline SiteSelector.java (4 of 5) Line 87 Program output Use Applet method getParameter to obtain the next site title

11 Outline SiteSelector.java (5 of 5) Program output

Manipulating URLs HTML frames – Specify target frame in method showDocument _blank _self _top

Reading a File on a Web Server Swing GUI component JEditorPane – Render both plain text and HTML-formatted text – Act as a simple Web browser Retrieves files from a Web server at a given URI HyperlinkEvent s – Occur when the user clicks a hyperlink – Three event types HyperlinkEvent.EventType.ACTIVATED HyperlinkEvent.EventType.ENTERED HyperlinkEvent.EventType.EXITED

14 Outline ReadServerFile.java (1 of 3) Lines 7, 12 and 13 Line 18 Import JEditPane from package javax.swing, import HyperlinkEvent and HyperlinkListener from package javax.swing.event Declare JEditorPane contentsArea, which will be used to display the contents of the file

15 Outline ReadServerFile.java (2 of 3) Line 40 Line 41 Lines Lines Lines Line 50 Create JEditorPane using the no-argument constructor Set JEditorPane editable property to false Register a HyperlinkListener to handle HyperlinkEvents, which occur when the user clicks a hyperlink in the JEditorPane Method hyperlinkUpdate is called when a HyperlinkEvent occurs Use HyperlinkEvent method getEventType to determine the type of the HyperlinkEvent Use HyperlinkEvent method getURL to obtain the URL represented by the hyperlink

16 Outline ReadServerFile.java (3 of 3) Line 65 Invoke JEditorPane method setPage to download the document specified by location and display it in the JEditPane

17 Outline ReadServerFileTest.java (1 of 2) Program output

18 Outline ReadServerFileTest.java (2 of 2) Program output

Establishing a Simple Server Using Stream Sockets Five steps to create a simple server in Java – Step 1: Create ServerSocket object ServerSocket server = new ServerSocket( portNumber, queueLength ); Register an available port Specify a maximum number of clients Handshake point Binding the server to the port – Only one client can be bound to a specific port

Establishing a Simple Server Using Stream Sockets (Cont.) Five steps to create a simple server in Java – Step 2: Server listens for client connection Server blocks until client connects Socket connection = server.accept(); – Step 3: Sending and receiving data OutputStream to send and InputStream to receive data – Method getOutputStream returns Socket ’s OutputStream – Methods getInputstream returns Socket ’s InputStream

Establishing a Simple Server Using Stream Sockets (Cont.) Five steps to create a simple server in Java – Step 4: Process phase Server and Client communicate via streams – Step 5: Close streams and connections Method close

Establishing a Simple Client Using Stream Sockets Four steps to create a simple client in Java – Step 1: Create a Socket to connect to server Socket connection = new Socket ( serverAddress, port ); – Step 2: Obtain Socket ’s InputStream and Outputstream – Step 3: Process information communicated – Step 4: Close streams and connection