1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| // affichage de message
while (listening) {
if (con.ready()){
byte[] b = new byte[1000];
con.receive(b);
String s = new String(b, 0, b.length);
System.out.println("Recieved from client: " + s.trim());
midlet.setAlert(s.trim());
send("Le nom du serveur est : " + getName());
askMsg();
System.out.println("server:"+message);
listening=false;
}
}
} catch(BluetoothStateException e){System.out.println(e);} catch(IOException f){System.out.println(f);}
}
/* fonction d'envoi du message */
private void send(String s){
byte[] b = s.getBytes();
try {
con.send(b);
} catch(IOException e){
System.out.println(e);
}
}
/* donne le nom de l'appareil */
private String getName(){
return deviceName;
}
protected void askMsg() {
Command cmd_ok = new Command("OK", Command.OK, 1);
String chaine=null;
Form form=null;
textb =new TextBox("","",50, TextField.ANY);
textb.setTitle("Entrez votre message");
textb.addCommand(cmd_ok);
textb.setCommandListener(this);
midlet.setCurrentDisplay(textb);
}
public void commandAction(Command c, Displayable d){
if (c.getCommandType()==Command.OK) {
message=textb.getString();
midlet.setCurrentDisplay(midlet.getList());
}
}
public void setMsg(String message){
this.message=message;
} |