Foundations of Python Network Programming
Chapter 7 ■ Server arChiteCture 117 A Simple Protocol To keep your attention on the various options presented by server design, ...
Chapter 7 ■ Server arChiteCture 118 def create_srv_socket(address): """Build and return a listening server socket.""" listener = ...
Chapter 7 ■ Server arChiteCture 119 The next two functions provide some common startup code that will be shared among the server ...
Chapter 7 ■ Server arChiteCture 120 for aphorism in random.sample(aphorisms, 3): sock.sendall(aphorism) print(aphorism, zen_util ...
Chapter 7 ■ Server arChiteCture 121 As usual with the server programs you wrote in Chapter 2 and Chapter 3, this server demands ...
Chapter 7 ■ Server arChiteCture 122 Finally, the single-threaded design makes poor use of the server CPU and system resources be ...
Chapter 7 ■ Server arChiteCture 123 There are two interesting technical details worth commenting on. One is the fact that the fi ...
Chapter 7 ■ Server arChiteCture 124 def start_threads(listener, workers=4): t = (listener,) for i in range(workers): Thread(targ ...
Chapter 7 ■ Server arChiteCture 125 class ZenHandler(BaseRequestHandler): def handle(self): zen_utils.handle_conversation(self.r ...
Chapter 7 ■ Server arChiteCture 126 Listing 7-6 shows the complete internals of a raw asynchronous server for your simple Zen pr ...
Chapter 7 ■ Server arChiteCture 127 Incoming data: keep receiving until we see the suffix. elif event & select.POLLIN: more_ ...
Chapter 7 ■ Server arChiteCture 128 When the client socket itself is then presented to you with a POLLIN event, you recv() up t ...
Chapter 7 ■ Server arChiteCture 129 The asyncio framework supports two programming styles. One, which reminds programmers of the ...
Chapter 7 ■ Server arChiteCture 130 You can see that the actual socket object is carefully protected from the protocol code in L ...
Chapter 7 ■ Server arChiteCture 131 if not more_data: if data: print('Client {} sent {!r} but then closed' .format(address, data ...
Chapter 7 ■ Server arChiteCture 132 Listing 7-9. Using the Old asyncore Framework !/usr/bin/env python3 Foundations of Python Ne ...
Chapter 7 ■ Server arChiteCture 133 One last time, you see that asynchronous frameworks, unless they do invisible magic like gev ...
Chapter 7 ■ Server arChiteCture 134 Listing 7-10. Answer a Single Client, Whose Socket Is the stdin/stdout/stderr !/usr/bin/env ...
Chapter 7 ■ Server arChiteCture 135 listener.settimeout(8.0) try: zen_utils.accept_connections_forever(listener) except socket.t ...
137 Chapter 8 Caches and Message Queues This chapter, though brief, might be one of the most important in this book. It surveys ...
«
2
3
4
5
6
7
8
9
10
11
»
Free download pdf