We want to make information available to others
Understanding how a web server works will help us do this
Most networked computers use [%g internet_protocol “Internet Protocol (IP)” %]
Defines multiple layers on top of each other
[%g tcp “Transmission Control Protocol (TCP/IP)” %] makes communication between computers look like reading and writing files
A [%g socket “sockets” %] is one end of a point-to-point communication channel
[%g ip_address “IP address” %] identifies machine
93.184.216.34[%g port “port” %] identifies a specific connection on that machine
A number in the range 0–65535
Some numbers reserved for well-known applications
E.g., port 80 is usually a web server
IP addresses are hard to remember
[%g dns “Domain Name System (DNS)” %] translates names like
third-bit.com into numerical identifiers
A [%g client “client” %] sends requests and processes responses (e.g., web browser)
A [%g server “server” %] waits for requests and replies to them (e.g., a web server)
[%inc client_all.py %]
[%inc server_raw.py omit=main %]
[% figure slug=“ftp-interaction” img=“interaction.svg” alt=“Client/server interaction” caption=“Steps and messages in client/server interaction.” %]
[%inc server_lib.py %]
Server uses self.request.recv(CHUNK_SIZE)
What if client sends more data than that?
Allocating a larger [%g buffer_memory “buffer” %] just delays the problem
Better solution: keep reading until there is no more data
[%inc server_chunk.py mark=class %]
[%inc client_chunk.py mark=send %]
Try to send all remaining data
Advance marker by amount actually sent and re-try
[%inc client_chunk.out %]
[%inc server_chunk.out %]
[%inc logging_handler.py mark=class omit=debug %]
[%inc logging_handler.py mark=debug %]
[%inc test_server.py mark=handler %]
Don’t upcall constructor of
LoggingHandler
Don’t want to trigger all of the library’s socket machinery
A constructor that records the data we’re going to pretend to have received over a socket and does other setup
A recv method with the same signature as the real
object’s
A sendall method whose signature matches the real
thing’s
[%inc test_server.py mark=request %]
[%inc test_server.py mark=test %]
[% figure slug=“ftp-concept-map” img=“concept_map.svg” alt=“Concept map of web server” caption=“Concept map.” %]