mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
Reindent code
This commit is contained in:
parent
58aa6f70a1
commit
98c048041d
1 changed files with 30 additions and 28 deletions
|
|
@ -213,37 +213,39 @@ Assuming you don't want to end the connection, the simplest solution
|
||||||
is a fixed length message:
|
is a fixed length message:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
class mysocket:
|
class mysocket:
|
||||||
'''demonstration class only
|
'''demonstration class only
|
||||||
- coded for clarity, not efficiency'''
|
- 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):
|
def __init__(self, sock=None):
|
||||||
self.sock.connect((host, port))
|
if sock is None:
|
||||||
|
self.sock = socket.socket(
|
||||||
|
socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
else:
|
||||||
|
self.sock = sock
|
||||||
|
|
||||||
def mysend(self, msg):
|
def connect(self, host, port):
|
||||||
totalsent = 0
|
self.sock.connect((host, port))
|
||||||
while totalsent < MSGLEN:
|
|
||||||
sent = self.sock.send(msg[totalsent:])
|
|
||||||
if sent == 0:
|
|
||||||
raise RuntimeError, \\
|
|
||||||
"socket connection broken"
|
|
||||||
totalsent = totalsent + sent
|
|
||||||
|
|
||||||
def myreceive(self):
|
def mysend(self, msg):
|
||||||
msg = ''
|
totalsent = 0
|
||||||
while len(msg) < MSGLEN:
|
while totalsent < MSGLEN:
|
||||||
chunk = self.sock.recv(MSGLEN-len(msg))
|
sent = self.sock.send(msg[totalsent:])
|
||||||
if chunk == '':
|
if sent == 0:
|
||||||
raise RuntimeError, \\
|
raise RuntimeError, \\
|
||||||
"socket connection broken"
|
"socket connection broken"
|
||||||
msg = msg + chunk
|
totalsent = totalsent + sent
|
||||||
return msg
|
|
||||||
|
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}
|
\end{verbatim}
|
||||||
|
|
||||||
The sending code here is usable for almost any messaging scheme - in
|
The sending code here is usable for almost any messaging scheme - in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue