0
AndroidアプリケーションとPythonでソケット付きのサーバ間の通信を確立する必要があります。アプリケーションクライアント(android java) - サーバ(Python)
クライアントは文字列でサーバーの返信を終了します。ここで
は私のサーバーのコードです:
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()
私はPythonでクライアントと通信するためにそれを行うことができたが、今私は、Androidクライアントをしなければなりません。 どうすればいいですか?