Ich muss eine Kommunikation zwischen einer Android-Anwendung und einem Server in Python mit Sockets einrichten.App-Client (Android Java) - Server (Python)
Der Client sendet ein Foto und beendet die Antwort des Servers mit einer Zeichenfolge.
Hier ist mein Server Code:
import socket
import os
import subprocess
s = socket.socket()
host = "10.255.20.186" # Get local machine name
port = 9090 # Reserve a port for your service.
s.bind((host,port))
s.listen(4) #number of people than can connect it
# os.system("python C:\\Users\\Federica\\PycharmProjects\\client-server\\Client2.py")
sc, address = s.accept()
print "Connected by: " , address
sb = 'C:\\Users\\Federica\\PycharmProjects\\client-server\\ricevi'
#os.chdir(sb)
fln=sb + os.sep + sc.recv(8) #read the name of the file
print fln
f = open(fln,'wb') #create the new file
size = sc.recv(5) #receive the size of the file
#size=size[:7]
print size
strng = sc.recv(int(size)) #receive the data of the file
#if strng:
f.write(strng) #write the file
f.close()
# here I send the photo to Matlab
cmd = '"matlab" -wait -nodesktop -nosplash -minimize -r "cd C:\\Users\\Federica\\PycharmProjects\\client-server\\; somma(\''+ fln + '\'); exit;"'
subprocess.call(cmd, shell=True)
imgPath = "C:\\Users\\Federica\\PycharmProjects\\client-server\\ricevi\\nuova.png"
print os.path.isfile(imgPath)
#subprocess.call('start \'' + imgPath + '\'')
sc.close()
s.close()
ich war in der Lage, es zu tun mit einem Client in Python zu kommunizieren, aber jetzt muß ich den Client in Android machen. Wie kann ich tun?