diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2006-08-09 14:06:19 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2006-08-09 14:06:19 (GMT) |
commit | 98c048041d91dc4694115e29b40182f89a3b9f1d (patch) | |
tree | b59825ba167ea5d2a57265262655eb622616dc4a | |
parent | 58aa6f70a1b0c4338c6a6d5484085b8e6d3327c1 (diff) | |
download | cpython-98c048041d91dc4694115e29b40182f89a3b9f1d.zip cpython-98c048041d91dc4694115e29b40182f89a3b9f1d.tar.gz cpython-98c048041d91dc4694115e29b40182f89a3b9f1d.tar.bz2 |
Reindent code
-rw-r--r-- | Doc/howto/sockets.tex | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/Doc/howto/sockets.tex b/Doc/howto/sockets.tex index 0607a93..0cecbb9 100644 --- a/Doc/howto/sockets.tex +++ b/Doc/howto/sockets.tex @@ -213,37 +213,39 @@ Assuming you don't want to end the connection, the simplest solution is a fixed length message: \begin{verbatim} - class mysocket: - '''demonstration class only - - coded for clarity, not efficiency''' - def __init__(self, sock=None): - if sock is None: - self.sock = socket.socket( - socket.AF_INET, socket.SOCK_STREAM) - else: - self.sock = sock - - def connect(self, host, port): - self.sock.connect((host, port)) - - def mysend(self, msg): - totalsent = 0 - while totalsent < MSGLEN: - sent = self.sock.send(msg[totalsent:]) - if sent == 0: - raise RuntimeError, \\ - "socket connection broken" - totalsent = totalsent + sent - - def myreceive(self): - msg = '' - while len(msg) < MSGLEN: - chunk = self.sock.recv(MSGLEN-len(msg)) - if chunk == '': - raise RuntimeError, \\ - "socket connection broken" - msg = msg + chunk - return msg +class mysocket: + '''demonstration class only + - coded for clarity, not efficiency + ''' + + def __init__(self, sock=None): + if sock is None: + self.sock = socket.socket( + socket.AF_INET, socket.SOCK_STREAM) + else: + self.sock = sock + + def connect(self, host, port): + self.sock.connect((host, port)) + + def mysend(self, msg): + totalsent = 0 + while totalsent < MSGLEN: + sent = self.sock.send(msg[totalsent:]) + if sent == 0: + raise RuntimeError, \\ + "socket connection broken" + totalsent = totalsent + sent + + def myreceive(self): + msg = '' + while len(msg) < MSGLEN: + chunk = self.sock.recv(MSGLEN-len(msg)) + if chunk == '': + raise RuntimeError, \\ + "socket connection broken" + msg = msg + chunk + return msg \end{verbatim} The sending code here is usable for almost any messaging scheme - in |