java - Best way to communicate between an Android App and a JavaFX Application -
i working on javafx music player can communicate android app via tcp sockets, displaying data music player (e.g.: playlist). android app loads list of available music players database. in list there the current ip , current public_port of music player. android app can connect player on tcp socket , public_port. after music player returns "private_port" android app (so app can communicate on private_port player), , starts listening new clients connect.
public void connecttoserver() { boolean end = false; for(int = 0; end == false; i++) { try { if(i > 100) { end = true; } socket = new java.net.socket(serveraddress,port); end = true; port = integer.parseint(getportfromserver()); log.d("", "connected engine on port" + port); socket.close(); socket = new java.net.socket(serveraddress,port); readplaylist(); thread.sleep(1000); } catch (ioexception e) { e.printstacktrace(); } catch (classnotfoundexception e) { e.printstacktrace(); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
because think not solution, because need alot of tcp ports wondering if there better method implement this.
my idea different implementation restful webservice, sure if work, because using javafx , need executable file launch music player without installing webserver.
edit: idea putting webserver between android app , javafx player. way solve port problem.
solved problem using udp sockets.
Comments
Post a Comment