I want to get out of loop when there is no data but loop seems to be stopping at recvfrom
image=''
while 1:
data,address=self.socket.recvfrom(512)
if data is None:break
image=image+data
count=count+1
print str(count)+' packets received...'
Try setting to a non-blocking socket. You would do this before the loop starts. You can also try a socket with a timeout.