1 Java Networking CS 236607, Spring 2008/9. 2 Today’s Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets URL 

Slides:



Advertisements
Similar presentations
Networking with Java 1. Introduction to Networking 2.
Advertisements

Network Programming Chapter 11 Lecture 6. Networks.
Prepared By E. Musa Alyaman1 URLs, InetAddresses, and URLConnections Chapter 9.
1 Java Networking – Part I CS , Spring 2008/9.
Networking Support In Java 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
Internet Programming In Java. References Java.sun.com Java552 Many of the programs shown.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Networking with Java 1: The Client Side. Introduction to Networking.
Projekt współfinansowany przez Unię Europejską w ramach Europejskiego Funduszu Społecznego „Networking”
28-Jun-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 Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
1 Java Networking – part I CS , Winter 2007/8.
Networking Support In Java 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Networking with Java. Introduction to Networking.
13-Jul-15 Sockets and URLs. 2 Sockets A socket is a low-level software device for connecting two computers together Sockets can also be used to connect.
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.
Network Programming in Java David Meredith Aalborg University.
Networking java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
1 Networking with Java. 2 Introduction to Networking.
1 Java Networking CS , Spring Today’s Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets URL  The.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
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.
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
Appendix F: Network Programming in Java ©SoftMoore ConsultingSlide 1.
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.
Chapter 1: Introduction to Web Applications. This chapter gives an overview of the Internet, and where the World Wide Web fits in. It then outlines the.
HTTP HTTP stands for Hypertext Transfer Protocol. It is an TCP/IP based communication protocol which is used to deliver virtually all files and other.
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.
4-Oct-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 send.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Import java.net.*; import java.io.*; public class LowPortScanner { public static void main(String[] args) { String host = "localhost"; if (args.length.
DBI Representation and Management of Data on the Internet.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
The Inter-network is a big network of networks.. The five-layer networking model for the internet.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
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.
A DVANCED P ROGRAMMING USING J AVA N ETWORKING B ASICS Prepared by / Nael Alian University of Palestine 1.
NETWORK PROGRAMMING.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens.
StreamTokenizer Break up a stream of text into pieces called tokens A token is the smallest unit recognized by a text parsing algorithm (words, symbols,
Java Programming: Advanced Topics 1 Networking Programming Chapter 11.
CS 4244: Internet Programming Network Programming in Java 1.0.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
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.
URL Programming Mimi Opkins CECS277. What is a URL?  URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Working with URLs CSIE, National University of Tainan.
Network Programming. These days almost all devices.
Network Programming Communication between processes Many approaches:
Secure Sockets SSL (Secure Sockets Layer) is a standard security technology for establishing an encrypted link between a server and a client—typically.
Network Programming Introduction
Network Programming Introduction
Sockets and URLs 17-Sep-18.
„Networking”.
Sockets and URLs 13-Nov-18.
Basic Protocols 24-Nov-18.
URL in Java C343 Lab (Week 13).
Networking.
Sockets and URLs 3-Dec-18.
Basic Protocols 19-Feb-19.
Socket Programming 2: Application Layer.
Uniform Resource Locator: URL
Presentation transcript:

1 Java Networking CS , Spring 2008/9

2 Today’s Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets URL  The java classes: URL, URLEncoder, URLConnection, HTTPURLConnection Datagrams Networking in JDBC

3 URL - Uniform Resource Locator Protocol Host Name Port Number Path & File Name Reference URL is a reference (an address) to a resource on the Internet.  A resource can be a file, a database query and more. URLs are just a subset of the more general concept of Uniform Resource Identifiers (URIs) which are meant to describe all points in the information space

4 Class URL Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. We distinguish between:  Absolute URL - contains all of the information necessary to reach the resource.  Relative URL - contains only enough information to reach the resource relative to (or in the context of) another URL.

5 Class URL Cont. Constructing URLs:  URL w3c1 = new URL("  URL w3c2 = new URL("http","  URL w3c3 = new URL(w3c2, "xhtml1/"); If the string is not an absolute URL, then it is considered relative to the URL More constructors can be found in the URL APIURL API

6 URL Encoding URL Encoding is the process of converting string into valid URL format. Valid URL format means that the URL contains only what is termed "alpha | digit | safe | extra | escape" characters.  You can read more about the what and the whys of these terms on the World Wide Web Consortium site:  URL Encoding Reference URL Encoding Reference

7 URL Encoding Cont. Among the rest, URL encoding is performed to convert data passed via html forms, because such data may contain special character, such as "/", ".", "#", and so on, which could either:  Have special meanings  Is not a valid character for an URL For instance, the "#" character needs to be encoded because it has a special meaning of that of an html anchor. The character also needs to be encoded because is not allowed on a valid URL format.

8 URL Encoding Cont. Example: The URL encoding of “This is a simple & short test” is “This+is+a+simple+%26+short+test “ Note that because the character is very commonly used, a special code ( the "+" sign) has been reserved as its URL encoding

9 URL addresses with Special characters Some URL addresses also contain these special characters, for example the space character.  Like this: world/ To make theses characters legal they need to be encoded before passing them to the URL constructor. URL url = new URL(" One class that can help us with this is the URI class : URI uri = new URI("http", "foo.com", "/hello world/", ""); URL url = uri.toURL(); Another one is the URLEncoder class…

10 URLEncoder Contains a utility method encode for converting a string into an encoded format (used in URLs) To convert a string, each character is examined in turn:  Space is converted into a plus sign +  a - z, A - Z, 0 - 9,., -, * and _ remain the same.  The bytes of all special characters are replaced by hexadecimal numbers, preceded with % To decode an encoded string, use decode() of the class URLDecoder The URLEncoder API. The URLEncoder API

11 MalformedURLException URL constructors throws a MalformedURLException if the arguments to the constructor refer to a null or unknown protocol. Typically, you want to catch and handle this exception by embedding your URL constructor statements in a try/catch pair, like this: try { URL myURL = new URL(...) } catch(MalformedURLException e) {... // exception handler code here... }

12 ImFeelingLucky Example The following program sends a request to the Google server and extracts the result. Google search engine accepts GET requests of a specific format. It’s reply always contain a Location header line if the search is successful.

13 ImFeelingLucky Example Cont. Finally would be the right place…

14 Parsing a URL The following methods of URL can be used for parsing URLs: getProtocol(), getHost(), getPort(), getPath(), getFile(), getQuery(), getRef()

15 import java.net.*; import java.io.*; public class ParseURL { public static void main(String[] args) throws Exception { URL aURL = new URL(" + "/index.html?name=networking#DOWNLOADING"); System.out.println("protocol = " + aURL.getProtocol()); System.out.println("authority = " + aURL.getAuthority()); System.out.println("host = " + aURL.getHost()); System.out.println("port = " + aURL.getPort()); System.out.println("path = " + aURL.getPath()); System.out.println("query = " + aURL.getQuery()); System.out.println("filename = " + aURL.getFile()); System.out.println("ref = " + aURL.getRef()); } The Output protocol = http authority = java.sun.com:80 host = java.sun.com port = 80 path = /docs/books/tutorial/index.html query = name=networking filename = /docs/books/tutorial/index.html?name=networking ref = DOWNLOADING

16 URLConnection Represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL. Creating a connection to a URL:  The connection object is created by invoking the openConnection method on a URL. If the protocol of the URL is HTTP, the returned object is of class HttpURLConnection.  The setup parameters and general request properties are manipulated.  The actual connection to the remote object is made, using the connect method.  The remote object becomes available. The header fields and the contents of the remote object can be accessed. See the URLConnection class API for more informationAPI

17 URLConnection Cont. The life cycle of a URLConnection object has two parts:  Before actual connection establishment Connection configuration ( setAllowUserInteraction, setDoInput and more)  After actual connection establishment Content retrieval Moving from the first phase to the second is implicit  A result of calling some committing methods, like getDate()

18 URLConnection Example What will happened if you will try to run this code while not connected to the web?

20 Class HttpURLConnection A URLConnection with support for HTTP- specific features.  responseMessage field  getRequestMethod()  usingProxy() There is no need to create HTTP parsers The HttpURLConnection API

21 Datagrams A datagram is an independent, self-contained message sent over the network whose arrival, arrival time, and content are not guaranteed. The java.net package contains three classes to help you write Java programs that use datagrams to send and receive packets over the network: DatagramSocket, DatagramPacket, and MulticastSocket DatagramSocketDatagramPacket MulticastSocket

22 Networking in JDBC You actually already met Sockets….

23 Can be anywhere! (not necessarily localhost – usually remote)

24 Resources The Java Tutorials – Sun Microsystems An Introduction to XML and Web Technologies / Anders Møller and Michael I. Schwartzbach – course literature Wikipedia