Public feed #601053

Someone

public text v1 · immutable
Raw Edit
·published 2007-07-03 08:02 UTC
rendered paste body
server
--------------------------------------
#!/usr/bin/env python

#-*- coding:utf-8 -*-

import cPickle
import socket
import signal

class myclass:
    def __init__(self):
        self.data = 'here is the string'



def on_int(one,two):
    pass
    


if __name__ == '__main__':
    a = myclass()

    host = '127.0.0.1'
    port = 40000
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((host,port))
    s.listen(5)
    signal.signal(signal.SIGINT, on_int)
    
    while 1:
        client,address = s.accept()
        f = client.makefile('w',0)
        b = cPickle.dump(a, f)
        client.close()
        



-------------------------
client
-------------------------
#!/usr/bin/env python

#-*- coding:utf-8 -*-

import socket
import cPickle



if __name__ == '__main__':
    host = '127.0.0.1'
    port = 40000
    size = 100
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host,port))
    f = s.makefile('r',0)
    try:
        a = cPickle.load(f)
    except Exception,e:
        print e
    f.close()


-------------------------------
error
-------------------------------
mg42% python client.py
'module' object has no attribute 'myclass'