Pertemuan 4 HTTP Protocol Matakuliah : T0053/Web Programming

advertisement
Matakuliah
Tahun
Versi
: T0053/Web Programming
: 2006
:2
Pertemuan 4
HTTP Protocol
1
Learning Outcomes
Pada akhir pertemuan ini, diharapkan mahasiswa
akan mampu :
• Menjelaskan konsep Web Protocol
• Menggunakan web server standar
2
Outline Materi
• Web Fundamentals
• Web protocol
• Web server
3
Web Fundamental
Web browsers and servers
– Internet is “just” a set of loosely interconnected
networks
– A set of local area networks connected via wide area
networks
– No centralized control or management
– Network segments interconnect via routers
– Routers are dedicated computers that manage
packets of data
– TCP/IP is the universal data protocol on the network
– Actual format, content is left to higher-level protocols,
like the Web (HTTP)
4
Web Server
• What is a web server?
– Program that responds to requests for
documents
• "http daemon"
– Uses the Hypertext Transfer Protocol (HTTP)
to communicate
– Physical machine which runs the program
5
Definition
• Daemon – UNIX speak
– A program that is not invoked explicitly, but
lies dormant waiting for some condition(s) to
occur
– The “httpd daemon” is an http server process
6
Web Server Basic
• Duties
– Listen to a port
– When a client is connected, read the HTTP
request
– Perform some lookup function
– Send HTTP response and the requested data
7
Serving a Page
• User of client machine types in a URL
client
(Netscape)
server
(Apache)
http://www.smallco.com/index.html
8
Serving a Page
• Server name is translated to an IP address
via DNS
client
(Netscape)
server
(Apache)
http:// www.smallco.com /index.html
192.22.107.5
9
Serving a Page
• Client connects to server using IP address and
port number
client
(Netscape)
192.22.107.5
port 80
server
(Apache)
http://www.smallco.com/index.html
192.22.107.5
10
Serving a Page
• Client determines path and file to request
client
(Netscape)
server
(Apache)
http://www.smallco.com/index.html
11
Serving a Page
Client sends HTTP request to server
client
(Netscape)
GET index.html HTTP/1.1
server
(Apache)
http://www.smallco.com/index.html
12
Serving a Page
• Server determines which file to send
client
(Netscape)
http://www.smallco.com/index.html
server
(Apache)
"index.html" is really
/etc/httpd/htdocs/index.html
13
Serving a Page
• Server sends response code and the
document
client
(Netscape)
HTTP/1.1 200 OK
Content-type: text/html
[contents of index.html]
server
(Apache)
http://www.smallco.com/index.html
14
Serving a Page
Connection is broken
client
(Netscape)
server
(Apache)
15
HTTP Protocol Definitions
• HTTP is…
– Designed for document transfer
– Generic
• not tied to web browsers exclusively
• can serve any data type
– Stateless
• no persistant client/server connection
16
IP Address
import java.net.*;
class CobaInetAddress
{
public static void main (String args[])
{
try
{
InetAddress a= InetAddress.getLocalHost();
System.out.println ("Nama Komputer dan IP ialah :" + a);
System.out.println ("Alamat host ialah " + a.getHostAddress());
System.out.println ("Nama host ialah " + a.getHostName());
}
catch (UnknownHostException u)
{
System.out.println ("Error " + u);
}}}
17
Display NIC
import java.io.*;
import java.net.*;
import java.util.*;
public class DisplayNIC {
public static void main (String argv[]) throws Exception
{
//Menggunakan method getNetworkInterface()
Enumeration e= NetworkInterface.getNetworkInterfaces();
//Perulangan untuk mengambil info NIC
while (e.hasMoreElements())
{
NetworkInterface n = (NetworkInterface)
e.nextElement();
System.out.println ("NIC :" + n.getName());
//Ambil semua info NIC
Enumeration e1= n.getInetAddresses();
while (e1.hasMoreElements ())
{
InetAddress i =(InetAddress) e1.nextElement();
System.out.println ("Alamat IP :" + i.toString());
}}}}
NIC : lan0
Alamat IP : /192.168.0.55
NIC : lo0
Alamat IP :/127.0.0.1
18
References
• Internet & WWW How to Program, Deitel & Deitel
• “Fundamental Web Design Principles”,
http://ausweb.scu.edu.au/aw99/papers/turner/paper.html
• Widodo Budiharto, “Panduan Lengkap Pemrograman
J2EE”, Andi Offset Yogyakarta 2006
• “Introduction to Web Programming 4 days”:
http://www.wdvl.com/Authoring/Scripting/Tutorial
• Introduction to Web Design 3 days:
http://www.wdvl.com/Authoring/HTML/Tutorial/index.html
• www.widodo.com
• http://www.w3schools.com
19
Download