Learning Python Network Programming
Client and Server Applications def prep_msg(msg): """ Prepare a string to be sent as a message """ msg += '\0' return msg.encode ...
Chapter 8 Of course, not all the data that we may want to send or receive over a network will be text. For example, images, comp ...
Client and Server Applications if __name__ == '__main__': listen_sock = tincanchat.create_listen_socket(HOST, PORT) addr = liste ...
Chapter 8 msg = tincanchat.recv_msg(sock) # Block until # received complete # message print('Received echo: ' + msg) except Conn ...
Client and Server Applications Concurrent I/O If you're adventurous, then you may have tried connecting to our server using more ...
Chapter 8 Multithreading and multiprocessing Python has APIs that allow us to write both multithreading and multiprocessing appl ...
Client and Server Applications When threads have operations to execute, they ask the operating system thread scheduler to alloca ...
Chapter 8 With this in mind, we're going to use multithreading rather than multiprocessing in our echo server. The shared data m ...
Client and Server Applications A multithreaded echo server A benefit of the multithreading approach is that the OS handles the t ...
Chapter 8 You can see that we've just imported an extra module and modified our main loop to run our handle_client() function in ...
Client and Server Applications A chat protocol The main purpose of our protocol update will be to specify that clients must be a ...
Chapter 8 So, we'll use a push approach, and we will now write our chat protocol as follows: Communication will be conducted ov ...
Client and Server Applications Notice that recv 1 and recv 2, when taken together contain a complete message, but they also cont ...
Chapter 8 The rest value is important because we will feed it back to recv_msgs() next time we call it, and it will be prefixed ...
Client and Server Applications for msg in msgs: msg = '{}: {}'.format(addr, msg) print(msg) broadcast_msg(msg) def handle_client ...
Chapter 8 while True: client_sock,addr = listen_sock.accept() q = queue.Queue() with lock: send_queues[client_sock.fileno()] = q ...
Client and Server Applications Hang on, you might ask, earlier, didn't you say that because of the GIL the OS is running only on ...
Chapter 8 A Lock is either locked or unlocked. A thread can lock a thread by either calling acquire() on it, or as in our progra ...
Client and Server Applications while True: msg = input() # Blocks if msg == 'q': sock.shutdown(socket.SHUT_RDWR) sock.close() br ...
Chapter 8 Let's give our new programs a try. Fire up the multithreaded chat server, and then launch at least two clients. If you ...
«
7
8
9
10
11
12
13
14
15
16
»
Free download pdf