[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
data = self.request.recv(1024) # read, write a client socket if not data: break reply = 'Echo=>%s at %s' % (data, now()) self ...
simple but fully-functional HTTP (web) server that knows how to run server-side CGI scripts. We’ll explore those larger server t ...
However used, select lets us direct attention to sockets ready to communicate, so as to avoid blocking on calls to ones that are ...
portsock.bind((myHost, myPort)) # bind it to server port number portsock.listen(5) # listen, allow 5 pending connects mainsocks. ...
Running the select server Let’s run this script locally to see how it does its stuff (the client and server can also be run on d ...
C:\Users\mark\Stuff\Books\4E\PP4E\dev\Examples\PP4E\Internet\Sockets>python sele ct-server.py select-server loop starting Con ...
numbers to express fractions of a second), a zero value to mean simply poll and return immediately, or omitted to mean wait unti ...
supports both clients and servers and includes implementations of a number of commonly used network services such as a web serve ...
Making Sockets Look Like Files and Streams So far in this chapter, we’ve focused on the role of sockets in the classic client/se ...
recv calls, and might offer more flexibility for software that must support a variety of transport mechanisms. See Chapter 17 fo ...
""" sock = socket(AF_INET, SOCK_STREAM) sock.connect((host, port)) # caller operates in client mode file = sock.makefile('w') # ...
Example 12-11. PP4E\Internet\Sockets\test-socket_stream_redirect.py """ ######################################################## ...
data = file.readline().rstrip() conn.send(('server %s got [%s]\n' % (mypid, data)).encode()) def client3(): mypid = os.getpid() ...
test by number on command-line ############################################################################### if name == 'main' ...
such as the print built-in that writes text strings (as we’ve learned, binary mode files require byte strings instead). When dea ...
only avoids wait states for transfer calls and does not address the data producer’s failure to send buffered output. Stream requ ...
Traceback (most recent call last): File "C:\...\PP4E\Internet\Sockets\test-stream-modes.py", line 26, in <module> writer( ...
msg = conn.recv(1024) # blocks till data received print(msg) # gets all print lines at once unless flushed The client in Example ...
C:\...\PP4E\Internet\Sockets> socket-unbuff-server.py accepting... receiving... b'spam\r\n' receiving... b'eggs\r\n' receivin ...
The latter option may be more direct (and the redirection utility module also returns the raw socket in support of such usage), ...
«
39
40
41
42
43
44
45
46
47
48
»
Free download pdf