



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to web programming, focusing on the concepts of distributed systems and the hypertext transfer protocol (http) for data exchange. It covers the basics of sockets, client-server architecture, and http requests and responses. Students will learn about the differences between distributed and unitary systems, the importance of handling concurrency and partial failure, and the role of standards like ip, udp, and tcp in internet communication.
Typology: Study Guides, Projects, Research
1 / 35
This page cannot be seen from the preview
Don't miss anything!




























Web Client Programming
[harry@nisl ~]$ mkdir webprog [harry@nisl ~]$ cd webprog [harry@nisl webprog]$ tar xvfz /home/csci553/classfiles/webprog.tgz ./ ./spider.py ./urllibex.py ...
(^) Programmers build small pieces, then connect them in arbitrary ways
(^) Low cost of entry: it's easy to add one more tool to the toolbox (^) Common data format: stream of strings (^) Common communication protocol: stdin, stdout, and zero/nonzero exit codes
(^) Everything used HTML (data format) over HTTP (communication protocol)
(^) Asymmetric: clients ask for things, servers provide them Web servers are the best-known examples (^) But database management systems are also servers
(^) Symmetric: every participant both provides and receives data
(^) But if the server fails, the whole system fails
import sys, socket buffer_size = 1024 # bytes host = '127.0.0.1' # local machine port = 19073 # hope nobody else is using it... message = 'ping!' # what to send
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, port))
sock.send(message)
data = sock.recv(buffer_size) print 'client received', data
sock.close()
Figure 13.2: HTTP Request Cycle
(^) Clients are typically browsers, such as Firefox and Internet Explorer (^) Apache is the most widely used server, but many others exist
(^) Or an error message
(^) Server doesn't remember anything between requests (^) Every image in a web page must be requested and downloaded separately
601 Connection Timed Out The server did not respond before the connection timed out 500 Internal Server Error An error occurred in the server that prevented it fulfilling the request 408 Timeout The server gave up waiting for the client 404 Not Found The requested resource could not be found 401 Unauthorized The request requires authentication 400 Bad Request The request is badly formatted 307 Temporary Redirect The requested resource is temporarily at a different location 301 Moved Permanently The requested resource has moved to a new permanent location 204 No Content The server has completed the request, but doesn't need to return any data 200 OK The request has succeeded 100 Continue Client should continue sending data Code Name Meaning
(^) Fetch a page from the course site (^) Request has no headers, so the blank line that signals “end of headers” is right after the request line import sys, socket buffer_size = 1024 HttpRequest = '''GET /greeting.html HTTP/1. ''' sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('www.third-bit.com', 80)) sock.send(HttpRequest) response = '' while True: data = sock.recv(buffer_size) if not data: break response += data sock.close() print response (^) Note: the double parentheses in the call to sock.connect are deliberate (^) Method's argument is a (host, port) tuple