Socket Programming HOWTO example
Steve Holden
steve at holdenweb.com
Mon Jan 16 07:46:13 EST 2006
Marco Meoni wrote:
> Hi. I read the Gordon McMillan's "Socket Programming Howto".
> I tried to use the example in this howto but this doesn't work.
> The code is class mysocket:
> '''classe solamente dimostrativa
> - codificata per chiarezza, non per efficenza'''
> 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(host, port):
> self.sock.connect((host, port))
> def mysend(msg):
> totalsent = 0
> while totalsent < MSGLEN:
> sent = self.sock.send(msg[totalsent:])
> if sent == 0:
> raise RuntimeError, \\
> "connessione socket interrotta"
> totalsent = totalsent + sent
> def myreceive():
> msg = ''
> while len(msg) < MSGLEN:
> chunk = self.sock.recv(MSGLEN-len(msg))
> if chunk == '':
> raise RuntimeError, \\
> "connessione socket interrotta"
> msg = msg + chunk
> return msg
>
> How can i use this?
Well, a lot depends on what you mean by "doesn't work".
I can see you have changed the example a little (because I know that
Gordon's original didn't have comments in Italian). Did the program
produce a syntax error, a traceback or what? It would have been helpful
if you had included a link to Gordon's tutorial -- I presume you mean
the one at
http://www.amk.ca/python/howto/sockets/
What are you trying to do, and why do you think this particular chunk of
code might help you? Did you actually try to create and use any
instances of this class?
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list