3 messages in com.googlegroups.android-beginnersRe: Tcp socket within 2 emulators
FromSent OnAttachments
strate0123423 Mar 2008 04:02 
en3rgizer25 Mar 2008 09:11 
strate0123425 Mar 2008 09:58 
Subject:Re: Tcp socket within 2 emulators
From:strate01234 (adam@strath.ac.uk)
Date:03/25/2008 09:58:40 AM
List:com.googlegroups.android-beginners

Hi :),

Here is the main code of the client:

try { Socket socket = new Socket("10.0.2.2",port); // System.out.println("SOCKET = " + socket);

BufferedReader plec = new BufferedReader( new InputStreamReader(socket.getInputStream()) );

PrintWriter pred = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())), true);

String str = "bonjour"; for (int i = 0; i < 5; i++) { pred.println(str); // envoi d'un message str = plec.readLine(); tv.append(str);// lecture de l'écho try{ Thread.sleep(1000); }catch (InterruptedException e){ } }

// System.out.println("END"); // message de terminaison pred.println("END") ; plec.close(); pred.close(); socket.close();

} catch (IOException e){ e.printStackTrace(); }

Try with IP adress maybe it cannot solve "en3rgizer", "10.0.2.2" is the adress given by the emulator for your computor (because the localhost for the emulator is the emulator) and you need to have a server app which is listenning.

For the rest I solve my problem, to communicate within two emulators you have to connect with the consol of one of the emulator and type "redir add tcp:portComputer:portEmulator" then all the data arriving on the port "portComputer" of your computer will be send to the virtual port "portEmulator" of the emulator. So if the emulator is listenning on the port "portEmulator" then you can connect with another emulator by connecting on the "portComputer". I dont really know if I made myself clear, sorry for my english :).