Socket Programming HOWTO example

Marco Meoni meonimarco at gmail.com
Mon Jan 16 12:11:45 CET 2006


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?
Thanks all!
Marco




More information about the Python-list mailing list