Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tiny http client and server

Similar presentations


Presentation on theme: "Tiny http client and server"— Presentation transcript:

1 Tiny http client and server
Spring 2015 Rakesh Palacherla Instructor: Dr. James Fawcett

2 Project Requirements Build a Http Server and Http Client Components based on sockets using HTTP 1.0 protocol both on Windows and Linux. Shall support Traditional Two-Way and One-Way communication Sockets package that support both ipv4 and ipv6 Develop a Chat application that use the Http client and server components between processes and machines.

3 HTTP- Hypertext Transfer Protocol
 It's the network protocol used to deliver virtually all files and other data on the World Wide Web, whether they're HTML files, image files, query results, or anything else. Usually, HTTP takes place through TCP/IP sockets.  HTTP uses the client-server model: An HTTP client opens a connection and sends a request message to an HTTP server; the server then returns a response message, usually containing the resource that was requested. After delivering the response, the server closes the connection

4 Structure of http transactions
The format of request and response messages are similar .Both kind of messages consist of Initial line Zero or more header lines A blank line Optional message body Initial Request line looks as below GET /path HTTP/1.0 GET is the most common HTTP method .It says give me the resource. Other methods include POST, PUT, DELETE and HEAD The path is the part of the URL after the host name, also called the request UR HTTP/x.x shows the version of HTTP. Initial Response line looks as below HTTP/ OK The status code is meant to be computer-readable; the reason phrase is meant to be human-readable

5 The status code is a three-digit integer, and the first digit identifies the general category of response: 1xx indicates an informational message only 2xx indicates success of some kind 3xx redirects the client to another URL 4xx indicates an error on the client's part 5xx indicates an error on the server's part Some of the status codes are 200- OK 404- Not Found

6 HTTP 1.1 It is the superset of HTTP 1.0. Improvements include:
Faster response for dynamically-generated pages, by supporting chunked encoding, which allows a response to be sent before its total length is known. Efficient use of IP addresses, by allowing multiple domains to be served from a single IP address. Faster response, by allowing multiple transactions to take place over a single persistent connection Faster response and great bandwidth savings, by adding cache support.

7 Chunked Transfer-Encoding
If a server wants to start sending a response before knowing its total length ,it might use the simple chunked transfer encoding ,which breaks the complete response into smaller chunks and sends them in series .It contains “Transfer-Encoding: chunked” header. A chunked message body contains a series of chunks, followed by a line with "0" (zero), followed by optional footers (just like headers), and a blank line. Each chunk consists of two parts: a line with the size of the chunk data, in hex, possibly followed by a semicolon and extra parameters and ending with CRLF. the data itself, followed by CRLF.

8 Persistent Connections and the "Connection: close" Header
In HTTP 1.0 and before, TCP connections are closed after each request and response, so each resource to be retrieved requires its own connection Opening and closing TCP connections takes a substantial amount of CPU time, bandwidth, and memory. Persistent connections are the default in HTTP 1.1, so nothing special is required to use them. Just open a connection and send several requests in series (called pipelining), and read the responses in the same order as the requests were sent If a client includes the “Connection: close” header in the request then the connection will be closed after corresponding response.

9 Example of HTTP 1.1 response :
HTTP/ OK Date:Fri,31 Dec :59:00 GMT Content-Type: text/plain Transfer-Encoding: chunked 1a;some data Abcdefghijklmnopqrstuvwxyz 10 Some-footer: some-value Another-footer:another value [blank line]

10 Efficient use of IP address
Starting with HTTP 1.1, one server at one IP address can be multi- homed, i.e. two different domains can live on same server. So in order to identify the domain in particular server we must specify the host name the request is intended for. This improvement is very useful as we are quickly running out of IP addresses.

11 sockets Sockets provide a common interface to the various protocols supported by networks. They allow you to establish connections between machines to send and receive data. Sockets support the simultaneous connection of multiple clients to a single server machine.

12 sockets API WSAStartup - loads WS2_32.dll WSACleanup - unloads dll
socket - create socket object connect - connect client to server bind - bind server socket to address/port listen - request server to listen for connection requests accept - server accepts a client connection send - send data to remote socket recv - collect data from remote socket Shutdown - close connection closesocket - closes socket handle

13 tasks Build a client and server using sockets for communication and using HTTP protocol. Build components for both client and server in Windows and Linux. Use the Components in an application like chat between client and server. Which uses Http client and server components. Support both ipv4 and ipv6 for the sockets package.

14 references http://www.jmarshall.com/easy/http/
S14a.pdf


Download ppt "Tiny http client and server"

Similar presentations


Ads by Google