views:

24

answers:

0

Hi all,
I am trying to plot data that I receive over a socket. I am using "Matplotlib" as the plotting library and "cPickle" to serialize python objects.
When I run my code, plot window opens and hangs up. I have tried a couple of ways to get around it, but no help
Don't know if this might help, but...I am using "Python 2.7 - 32 bit" on Win 7(64-bit). Here is my code

def init_plot():
    matplotlib.pyplot.ion()
    figsrc = matplotlib.pyplot.figure()
    axsrc = figsrc.add_subplot(111, autoscale_on=True)

def plot(x,y,z=None):
    if z == None:
        pylab.plot(x,y)
    else:
        pylab.plot(x,y,z)
    pylab.show();

def unserialize(data):
    return pickle.loads(data)

def init_socket():
    global UDPSock,buf
    # Set the socket parameters
    host = "localhost"
    port = 21567
    buf = 10240
    addr = (host,port)

    # Create socket and bind to address
    UDPSock = socket(AF_INET,SOCK_DGRAM)
    UDPSock.bind(addr)
if __name__ == '__main__':
    init_plot()
    init_socket()
    while 1:
        data,addr = UDPSock.recvfrom(buf)
        temp = numpy.array(unserialize(data))
        plot(temp[0,:],temp[1,:])
    UDPSock.close()

Client code is working fine. I don't know if it is a 32-64 bit incompatibility or some code issue.

Thanks.

PS: I have tried "pyfunc's" suggestion of s.setblocking(flag) and socket.settimeout(value)...Still no help