def serverTCP(host, port,ACK): while 1: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((host, port)) s.listen(1) conn, addr = s.accept() print "##########################CAMBIO MISSION###############################" print 'CAMBIO MISSION Connection address:', addr data = conn.recv(1024) if not data: break #print "received data:", data buffer3 = map(ord,data) print "CAMBIO MISSION received data:", messaggi.deserializzaMissionDATA(buffer3) conn.send(ACK) #conn.close() #s.close() print "##########################END MISSION###############################" # echo
def ReceiveTCP(TCP_PORT, ACK): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # UDP sock.bind((ReceiveTCP_IP, TCP_PORT)) sock.listen(3) conn, addr = sock.accept() print 'Connection address:', addr MESSAGE1 = conn.recv(10) print 'Prima ricezione: ',MESSAGE1 MESSAGE2 = conn.recv(14) print 'Seconda ricezione: ',MESSAGE2 MESSAGE3 = conn.recv(2048) print 'Terza ricezione: ',MESSAGE3 print len(ACK) conn.send(ACK) # echo conn.close() sock.close() buffer1 = map(ord,MESSAGE1) messaggi.deserializzaCommandDATA(buffer1) buffer2 = map(ord,MESSAGE2) print "lenb",len(buffer2) NID_OPERATIONAL = messaggi.deserializzaCommandDATA(buffer2) buffer3 = map(ord,MESSAGE3) print "received data:", messaggi.deserializzaMissionDATA(buffer3) return NID_OPERATIONAL