vmware - How to communicate with a Virtual Machine in Java? -
i made little java program check if pin code correct or not. can see in code, program asks enter pin code, checks in bdd.txt file (playing database role) if pin correct or not.
acutally want go next step, want deploy program on android device.
at first, need bdd.txt file on virtual machine (such ubuntu example) won't local anymore. more realistic. have keep in mind in future, device ask if pin entered or not, , of course pins won't on device, checking process won't local.
that why question : how communicate virtual machine in java ? program running on windows computer, have installed unbuntu vmware, how can reach file in vm ? (web services ?) possible ? , if yes, how ?
thank you. florent
the code :
import java.io.*; import java.util.*; public class main { // fonction permettant d'accéder/lire notre bdd de pins (fichier .txt) static public boolean readpinsdata(file datafile, arraylist<integer> data) { boolean err = false; try { scanner scanner = new scanner(datafile); string line; while (scanner.hasnext()) { line = scanner.nextline(); try { data.add(integer.parseint(line)); } catch (numberformatexception e) { e.printstacktrace(); err = true; } } scanner.close(); } catch (filenotfoundexception e) { e.printstacktrace(); err = true; } return err; } public static void main(string[] args) { // définition int & booléen nécessaires ici system.out.println("-----------------------"); system.out.println("applications besoins"); system.out.println("-----------------------"); console console = system.console(); //system.out.println(console == null); int pinsize = 0; int nbtry = 0; boolean authenticated = false; // on va demander à saisir un pin de 4 digits : tant que l'utilisateur // ne saisit pas 4 digits, on boucle { { char passwordarray[] = console.readpassword("enter pin: "); // demande // de // saisie // du // pin pinsize = passwordarray.length; if (pinsize != 4) { // on prévient l'utilisateur que le pin se // compose de 4 chiffres, sinon ok on passe // à la vérif. system.out.println("pin must 4 digits"); } else { system.out.println("checking..."); } arraylist<integer> pins = new arraylist<integer>(); // nos pins // sont mis // dans un // liste readpinsdata(new file("bdd.txt"), pins); // on lit dans notre // bdd de pins // system.out.println(pins); // system.out.println(passwordarray); string[] thepins = new string[pins.size()]; (int = 0; < thepins.length; i++) { thepins[i] = pins.get(i).tostring(); } string passentered = string.valueof(passwordarray); (int = 0; < thepins.length; i++) { // recherche si pin // bon et on print // :) if (passentered.equals(thepins[i]) && pinsize == 4) { system.out.println(":)"); authenticated = true; break; } } } while (pinsize != 4); // si la on saisit un pin qui n'a pas 4 // chiffres, on ne peux valider la demande, // donc le nombre d'essais n'est pas déduit if (!authenticated && pinsize == 4) { // dans ce cas, on incrémente // le nombre d'essais car le // pin saisit n'est pas dans // notre bdd et on print :( system.out.println(":("); nbtry++; } } while (nbtry < 3 && !authenticated); } }
the "database" :
1111 2222 3333 4444 5555 6666 7777 8888 9999
assuming virtual machine has been configured network connection, should have ip address other computer on network. open network connection other computer.
note virtual machines' network connections configured nat, meaning host computer has direct connection vm. if need connect somewhere other vm's host computer — such android device that's not emulator running on host — you'll need configure vm "bridged" networking, gives direct access lan.
Comments
Post a Comment