Introduction to Java Network Programming and HTTP

Slides:



Advertisements
Similar presentations
HTTP HyperText Transfer Protocol. HTTP Uses TCP as its underlying transport protocol Uses port 80 Stateless protocol (i.e. HTTP Server maintains no information.
Advertisements

HyperText Transfer Protocol (HTTP)
Application Layer-11 CSE401N: Computer Networks Lecture-4 Application Layer Overview HTTP.
1 HTTP and some other odds and ends Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
HyperText Transfer Protocol (HTTP) Computer Networks Computer Networks Spring 2012 Spring 2012.
9/16/2003-9/18/2003 The Application Layer and Java Programming September 16-18, 2003.
Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley, July.
Web, HTTP and Web Caching
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
EEC-484/584 Computer Networks Lecture 4 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
Client, Server, HTTP, IP Address, Domain Name. Client-Server Model Client Bob Yahoo Server yahoo.com/finance.html A text file named finance.html.
 What is it ? What is it ?  URI,URN,URL URI,URN,URL  HTTP – methods HTTP – methods  HTTP Request Packets HTTP Request Packets  HTTP Request Headers.
PL-IV- Group A HTTP Request & Response Header
Rensselaer Polytechnic Institute CSC-432 – Operating Systems David Goldschmidt, Ph.D.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Web Server Design Week 5 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/10/10.
HTTP Protocol Specification
Telecooperation Technische Universität Darmstadt Copyrighted material; for TUD student use only Internet Standards: Julian Schröder-Bernhardi, Dirk.
CS 3830 Day 7 Introduction : Application Layer 2 Processes communicating Process: program running within a host. r within same host, two processes.
FTP (File Transfer Protocol) & Telnet
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
2: Application Layer1 CS 4244: Internet Software Development Dr. Eli Tilevich.
Application Layer 2 Figures from Kurose and Ross
Rensselaer Polytechnic Institute Shivkumar Kalvanaraman, Biplab Sikdar 1 The Web: the http protocol http: hypertext transfer protocol Web’s application.
20-1 Last time □ NAT □ Application layer ♦ Intro ♦ Web / HTTP.
Week 11: Application Layer1 Web and HTTP First some jargon r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file,…
Maryam Elahi University of Calgary – CPSC 441.  HTTP stands for Hypertext Transfer Protocol.  Used to deliver virtually all files and other data (collectively.
2: Application Layer1 Web and HTTP First some jargon Web page consists of base HTML-file which includes several referenced objects Object can be HTML file,
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.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Proxy Lab Recitation I Monday Nov 20, 2006.
1 HTTP EECS 325/425, Fall 2005 September Chapter 2: Application layer r 2.1 Principles of network applications m app architectures m app requirements.
Web Design & Development 1 Lec - 21 Umair Javed. Web Design & Development 2 Socket Programming.
CIS679: Lecture 13 r Review of Last Lecture r More on HTTP.
1-1 HTTP request message GET /somedir/page.html HTTP/1.1 Host: User-agent: Mozilla/4.0 Connection: close Accept-language:fr request.
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross.
WWW: an Internet application Bill Chu. © Bei-Tseng Chu Aug 2000 WWW Web and HTTP WWW web is an interconnected information servers each server maintains.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
Web Technologies Lecture 1 The Internet and HTTP.
Overview of Servlets and JSP
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 7 Omar Meqdadi Department of Computer Science and Software Engineering University of.
EEC-484/584 Computer Networks Lecture 4 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
HyperText Transfer Protocol (HTTP) Deepti Kulkarni CISC 856: TCP/IP and Upper Layer Protocols Fall 2008 Acknowledgements Professor Amer Richi Gupta.
Data Communication EDA344, DIT420 Description of Lab 1 and Optional Programming HTTP Assignment Bapi Chatterjee Prajith R G.
Week 11: Application Layer 1 Web and HTTP r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file,… r Web page consists.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Network Applications: HTTP/1.0
Lecture # 1 By: Aftab Alam Department Of Computer Science University Of Peshawar Internet Programming.
Block 5: An application layer protocol: HTTP
HTTP – An overview.
The Hypertext Transfer Protocol
Internet transport protocols services
Uniform Resource Locators
Introduction to Client/Server Design
Uniform Resource Locators (URLs)
CS 5565 Network Architecture and Protocols
Hypertext Transfer Protocol (HTTP)
Uniform Resource Locators
Socket Programming 2: Application Layer.
HTTP Hypertext Transfer Protocol
Presentation transcript:

Introduction to Java Network Programming and HTTP FG Telekooperation Dirk Bradler, Julian Schröder-Bernhardi :

Outline Hypertext Transfer Protocol – HTTP Java network programming Different versions Requests and responses Java network programming Opening sockets in Java Reading and writing with sockets :

HyperText Transfer Protocol – HTTP Origins in early 1990’s Three versions of HTTP HTTP/0.9 (name not official) The original protocol, never standardized Very simple, only one type of requests HTTP/1.0 First “real” HTTP protocol version, RFC 1945 Widely used by the first browsers Still quite a simple protocol HTTP/1.1 Current standardized version, RFC 2616 Extends HTTP 1.0 in many ways, backwards compatible :

HTTP Connections Non-persistent connections (HTTP/1.0) Use a new TCP connection for each object Example: HTML page with 10 images  11 TCP conns! Performance not good (TCP 3-way handshake, 2 extra RTTs) TCP slow start for each connection Persistent connections (HTTP/1.1) Keep connection open for several requests  no slow start Issue new request when old download finishes (extra RTT!) No slow start, except at very beginning Further improvement: Pipelining Send several requests without waiting for reply Continuous download! Most efficient, but not always widely supported/implemented :

HTTP Requests Example request: GET /index.html HTTP/1.1 Host: www.google.com Connection: close User-Agent: Mozilla 1.6 <CR><LF> Request line, header lines, possible body :

HTTP Request Format Method <sp> URL <sp> Version <cr> <lf> Request line Header field :<sp> Value <cr> <lf> ... Header lines Header field :<sp> Value <cr> <lf> <cr> <lf> Entity body :

HTTP Requests Method: GET, POST, HEAD, ... (see RFC 2616) Normal requests GET Retrieving web pages, images, etc. Simple forms also processed with GET Entity body in POST POST used for complicated forms (lot of info to handle) Contents of form in entity body Parameters from forms separated by & Example: field1=value1&field2=value2&... :

HTTP Responses Example response: HTTP/1.1 200 OK Date: Thu, 06 Aug 1998 12:00:15 GMT Connection: close Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 09:23:24 GMT Content-Length: 6821 Content-Type: text/html <CR><LF> (data data data data data) Status line, header lines, requested document :

The BufferedReader Problem Version <sp> Status <sp> Phrase <cr> <lf> Status line Header field :<sp> Value <cr> <lf> ... Header lines Header field :<sp> Value <cr> <lf> <cr> <lf> Entity body :

HTTP Responses Status code gives result Phrase for humans, only code is important! Typical status codes with standard phrases: 200 OK: Everything went fine, information follows 301 Moved Permanently: Document moved, new location in Location-header in response 400 Bad Request: Error in request 404 Not Found: Document does not exist on server 505 HTTP Version Not Supported: Requested protocol version not supported by server :

More about HTTP Above describes basic HTTP/1.0 Read RFC for information about different header fields and their meaning HTTP/1.1 adds lot of new headers and features :

Java Network Programming Network programming in Java in general much easier than in other languages... ...except some advanced things which are harder  E.g. setting socket options Java supports both TCP and UDP sockets Many different ways to read/write sockets Differentiates between text and binary  Often several correct ways to handle socket TIMTOWTDI: There Is More Than One Way To Do It :

Network Programming Guidelines Robustness Principle Be conservative in what you do; be liberal in what you accept from others. Key ingredient for interoperability Reformulation Follow the standards for things you send You may receive things that does not fully follow the standard But: If you receive crap, you should return a well-defined error, don‘t try to understand it :

Using TCP Sockets Client side: String host = host to contact Socket sock = new Socket(host, port); String host = host to contact Host can also be InetAddress instead of String int port = port to be used (e.g. 80 for HTTP) Server side ServerSocket sock = new ServerSocket(port); Listen for incoming connections Socket client = sock.accept(); :

Using UDP Sockets Same for client and server DatagramSocket sock = new DatagramSocket(); For server, give port number as argument Send packets with send() Receive packets with receive() UDP packets implemented in DatagramPacket-class :

Reading and Writing TCP Sockets Socket has InputStream and OutputStream Need to wrap other streams around them Some wrappers implement buffers Java has many different I/O Streams See Java API for others (e.g., reading files) Relevant for sockets: InputStreamReader, OutputStreamWriter BufferedReader, BufferedWriter DataInputStream, DataOutputStream :

Reading from a Socket Prossible code: InputStream is = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); Read text by calling br.readLine() Can be used only for reading text! Possible solution: Implement a Reader on your own without buffering to mix and match text and binary data! :

Writing to a Socket Typical code OutputStream os = socket.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(os); BufferedWriter bw = new BufferedWriter(osw); Write by calling one of many write()-functions See the different classes for different possibilities Can also write directly to OutputStream For Streams, Strings need to be converted to bytes with getBytes() Writer are only for text output! :

DataInputStream DataInputStream can read binary data from socket Also can send primitive data types Typical code InputStream is = socket.getInputStream(); DataInputStream dis = new DataInputStream(is); Read binary data with read() (see API for details) Bonus functionality: Read text with readLine() But: deprecated (does not work correctly in some cases), use in Praktikum results in a worse grade :

DataOutputStream DataOutputStream can be used to write Typical code: OutputStream os = socket.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); DataOutputStream can also write text and binary Has writeBytes()-function  no need for String.getBytes() :

Differences Between Output Streams?!? What is the difference between DataOutputStream and normal OutputStream wrapped with BufferedWriter? Answer: There is almost no difference in practice Some subtleties: Possible problems with conversion between 8-bit and 16-bit characters (e.g., DataInputStream.readLine()) Possible text/binary data issues Possible problems with buffering (use flush()) dos.writeBytes(str) vs. bw.write(str.getBytes()) No “correct” way, use either as long as it works Be careful not to get confused! :

Assignment 1 Java Network Programming :

Assignment Details Assignment sheet on the Web page of the Praktikum Milestones: TCP client and server Simple Web server Web server improvements Important: pay attention to error-semantics, be conservative (i.e. follow the RFC) in what you send Deadline for returning: 09.05.2007 at 15:00 To be returned: Code with comments, test cases used Send at bradler@tk.informatik.tu-darmstadt.de :

Questions? :