import thread
import socket

def myTCPserver(TCP_PORT):   
    TCP_IP = ''    
    BUFFER_SIZE = 64  
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((TCP_IP, TCP_PORT))
    while 1:             
        s.listen(1)    
        conn, addr = s.accept()
        print 'Connection address:', addr
        while 1:
            data = conn.recv(BUFFER_SIZE)
            if not data: break
            tagID =ord(data[4])
            gain=ord(data[5])
            #print "received data:", data            
            testInfo='tagID= %s  \tgain= %s' %(tagID,gain)            
            vc.callAction("OSD.ShowText",testInfo, None)
            #Does the device (client) expect some kind of response?
            #conn.send("ACK?") 
        conn.close()
        print 'conn closed'
    vc.callAction("OSD.ShowText","Server Aborted", None)
    
thread.start_new_thread( myTCPserver, (1000,) )