问题
I'm making an android app that i want to publish it on the app store, but the problem it's that i don't know if i can connect my android app to my python code with socket, if i am not on the same router. If i need to do some changes what are they or how can i do if i want that the android app that anyone could download on the app store connects to my python code that's in the same port. for know my code to connect the both programme are
try {
handler.post( new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),"start client", Toast.LENGTH_LONG).show();
}
} );
WifiManager manager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
ip = Formatter.formatIpAddress(manager.getConnectionInfo().getIpAddress());
String mess = h[0];
String messag_send=(mess+"<ip>"+ip);
sock = new Socket( "192.168", 5000 );
printWriter = new PrintWriter( sock.getOutputStream() );
printWriter.write(messag_send);
String line = "no";
printWriter.flush();
printWriter.close();
sock.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
and for the serveur
host, port = ('',5000)
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#face_cascade = cv2.CascadeClassifier('cascade/data/haarcascade_frontalface_alt.xml')
#recognizer = cv2.face.LBPHFaceRecognizer_create()
o=False
while o==False:
try:
socket.bind((host, port))
print("le serveur est démarré! o = true")
o=True
except OSError:
o=False
finally:
if(o is not False):
o=True
socket.listen(5)
conn, adress = socket.accept()
print("listening")
data= conn.recv(2048)
print("h" )
print(data)
socket.close()
来源:https://stackoverflow.com/questions/58547465/a-qestion-about-socket-on-different-router