import socket
import time  

host = "192.168.1.117"  
s = socket.socket()
s.bind((host, 5500))

while True:
    print "waiting client..."
    s.listen(1)  
  
    sc, addr = s.accept()
    
    all = ""

#    i=0                 #to avoid infinit loop
    cnt = 0;
    first = 0;
    while True:  
        recibido = sc.recv(1024)
        all = all + recibido
        cnt = len(all)        
        if first == 0:
            first = 1;
            lng = int(all[12:18])       # 6 bytes to get the frame size 
                 
#        i = i + 1
#        if cnt == lng or i == 30:
        if cnt == lng:
            break
        
        
        
    print "\nSize of frame:" + str(lng)
    print "\nNumber of bytes received:" + str(cnt)
     
sc.close()  
s.close()

#print len(recibido)