Kaydet (Commit) 98c04804 authored tarafından Andrew M. Kuchling's avatar Andrew M. Kuchling

Reindent code

üst 58aa6f70
...@@ -213,37 +213,39 @@ Assuming you don't want to end the connection, the simplest solution ...@@ -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( def __init__(self, sock=None):
socket.AF_INET, socket.SOCK_STREAM) if sock is None:
else: self.sock = socket.socket(
self.sock = sock socket.AF_INET, socket.SOCK_STREAM)
else:
def connect(self, host, port): self.sock = sock
self.sock.connect((host, port))
def connect(self, host, port):
def mysend(self, msg): self.sock.connect((host, port))
totalsent = 0
while totalsent < MSGLEN: def mysend(self, msg):
sent = self.sock.send(msg[totalsent:]) totalsent = 0
if sent == 0: while totalsent < MSGLEN:
raise RuntimeError, \\ sent = self.sock.send(msg[totalsent:])
"socket connection broken" if sent == 0:
totalsent = totalsent + sent raise RuntimeError, \\
"socket connection broken"
def myreceive(self): totalsent = totalsent + sent
msg = ''
while len(msg) < MSGLEN: def myreceive(self):
chunk = self.sock.recv(MSGLEN-len(msg)) msg = ''
if chunk == '': while len(msg) < MSGLEN:
raise RuntimeError, \\ chunk = self.sock.recv(MSGLEN-len(msg))
"socket connection broken" if chunk == '':
msg = msg + chunk raise RuntimeError, \\
return msg "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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment