# ******************************************************** #Send Image Information via UDP packet in the format "IMAGE_NAME,IMAGE_SIZE" udpClient.sendUDPmsg(imgname + ',' + str(size), RPI_IP, UDP_PORT) #Assert that message with Image Name and Image Size was received ret = udpClient.receiveUDPmsg(delay) print "[ImageSource] Mensagem recebida do MidiSource", ret # ******************************************************** #Connect to RPI TCP server if (ret == "OK"): tcpClient = TCPClient(RPI_IP, TCP_PORT, BUFFER_SIZE) tcpClient.connectTCP() print '[ImageSource] TCP Client ready to send the image' #tcpClient.sendFileByNameAndClose(imgname) # ******************************************************** #Send Image tcpClient.sendDataBySize(img.read(), size) # ******************************************************** #Close TCP socket tcpClient.closeTCPclient() print '[ImageSource] TCPClient closed' #**************************MIDI PART****************************************** # ******************************************************** #Wait for UDP Packet Flag saying MIDI is ready to be sent ret = udpClient.receiveUDPmsg(delay) # ******************************************************** #Start TCP Server midi_data = ret.split(',') print '[ImageSource] Image Name: {0}, Image Size: {1}'.format( midi_data[0], midi_data[1]) # ********************************************************
# ******************************************************** #Send Image Information via UDP packet in the format "IMAGE_NAME,IMAGE_SIZE" udpClient.sendUDPmsg(imgname+','+str(size), RPI_IP, UDP_PORT) #Assert that message with Image Name and Image Size was received ret = udpClient.receiveUDPmsg(delay) print "[ImageSource] Mensagem recebida do MidiSource" , ret # ******************************************************** #Connect to RPI TCP server if(ret=="OK"): tcpClient = TCPClient(RPI_IP,TCP_PORT,BUFFER_SIZE) tcpClient.connectTCP() print '[ImageSource] TCP Client ready to send the image' #tcpClient.sendFileByNameAndClose(imgname) # ******************************************************** #Send Image tcpClient.sendDataBySize(img.read(), size) # ******************************************************** #Close TCP socket tcpClient.closeTCPclient() print '[ImageSource] TCPClient closed' #**************************MIDI PART****************************************** # ******************************************************** #Wait for UDP Packet Flag saying MIDI is ready to be sent ret = udpClient.receiveUDPmsg(delay) # ******************************************************** #Start TCP Server midi_data=ret.split(',') print '[ImageSource] Image Name: {0}, Image Size: {1}'.format(midi_data[0], midi_data[1]) # ******************************************************** #Accept RPI TCP connection
#size = os.path.getsize(midiname) print '[MidiSource] Sending name:"%s" and size:"%s",' % (midiname,str(size)) udpServer.sendUDPmsgToLastClient(midiname+','+str(size)+',') # ******************************************************** ret = udpServer.receiveUDPmsg(delay) print "[MidiSource] Mensagem recebida do ImageSource " , ret # ******************************************************** #Connect to Android TCP server on Android_IP and TCP_PORT if(ret=="OK"): tcpClient = TCPClient(imageSource_addr[0],TCP_PORT,BUFFER_SIZE) tcpClient.connectTCP() print '[MidiSource] TCP Client ready to send the MIDI' #tcpClient.sendFileByNameAndClose(imgname) # ******************************************************** #Send Image tcpClient.sendDataBySize(midi.read(), size) # ******************************************************** #Close TCP socket tcpClient.closeTCPclient() print '[MidiSource] TCPClient closed' # ******************************************************** #Send MIDI # ******************************************************** #If transfer has finished, Close TCP socket except: print sys.exc_info()[0] #raise finally: print >>sys.stderr, '[MidiSource] Exiting Program' try: