Android-dev.it Community

 
Annunci

:arrow: Benvenuto!, se non sei ancora un utente registrato: puoi registrati qui, oppure effettua il login
:arrow: Apri un forum sul tuo nuovo smartphone Android e collabora con noi! (dettagli)

www.agendadigitale.org
Image


Sponsor
It is currently Tue May 22, 2012 8:00 am

All times are UTC + 1 hour


 Topics   Replies   Views   Last post 
No new posts На интернет-витрине

by popowahgjfghjoiuyt on Sat May 19, 2012 2:25 pm in Amministrazione

0

12

Sat May 19, 2012 2:25 pm

popowahgjfghjoiuyt

No new posts Apri un forum sul tuo nuovo smartphone Android!

[ Go to page: 1, 2, 3 ]

by ReattileGar on Fri May 18, 2012 5:27 pm in Amministrazione

27

12514

Fri May 18, 2012 5:27 pm

ReattileGar

No new posts Новый: базы для хрумера - профессиональный софт для СЕО.

by Renatafe on Fri May 18, 2012 3:14 pm in Amministrazione

0

17

Fri May 18, 2012 3:14 pm

Renatafe

No new posts Pace is undoubtedly the vital affordable Jerseys Wholesale d

by barnettmmolive2012 on Wed May 16, 2012 7:36 am in Amministrazione

1

47

Wed May 16, 2012 7:36 am

barnettmmolive2012

No new posts with all of the association that congenita

by ienae on Tue May 15, 2012 4:55 am in Android

0

15

Tue May 15, 2012 4:55 am

ienae




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [RISOLTO]Comunicazione tra emulatori
PostPosted: Thu Oct 28, 2010 4:16 pm 
Offline
User avatar

Joined: Tue Jun 08, 2010 10:55 am
Posts: 15
Punti Android: ?
Ciao a tutti!
Volevo sapere se è possibile far comunicare due emulatori Android avviati su due macchine differenti collegate in rete.

Ad esempio:
- Emulatore A su una macchina M1
- Emulatore B su una macchina M2

A e B possono scambiarsi messaggi?

Se si quale indirizzo di rete va specificato?
Grazie mille
Deborah


Top
 Profile  
 
 Post subject: Re: Comunicazione tra emulatori
PostPosted: Thu Oct 28, 2010 4:56 pm 
Offline
Moderatore
User avatar

Joined: Thu Dec 27, 2007 3:51 pm
Posts: 986
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 1320
Ciao Deborah,
sì, si può fare ed è possibile farlo anche usando un solo PC fisico perchè si può fare il bind di ciascuna istanza dell' emulatore su una specifica porta TCP (***URLs are hidden from guests, please register and login to view the hyperlink***).
Io ad esempio mi sono divertito a simulare la chiamata voce di un emulatore verso l'altro (ovviamente viene simulato l'inoltro e la ricezione della chiamata ma non lo scambio vocale), trovi info qua:
***URLs are hidden from guests, please register and login to view the hyperlink***
***URLs are hidden from guests, please register and login to view the hyperlink***.
***URLs are hidden from guests, please register and login to view the hyperlink***

Oppure si può anche far comunicare un device fisico con l'emulatore.

Prova e se hai problema scrivi qua.

PS. Ma te sei la Deborah già iscritta prima con un altro username o no ?!?


Top
 Profile  
 
 Post subject: Re: Comunicazione tra emulatori
PostPosted: Thu Oct 28, 2010 5:06 pm 
Offline
User avatar

Joined: Tue Jun 08, 2010 10:55 am
Posts: 15
Punti Android: ?
Ciao,
ti ringrazio per la risposta! Però il mio problema non sono le porte ma gli indirizzi.
Il mio problema non è la comunicazione sul singolo PC ma su PC multipli. Sei sicuro che è possibile?
Mi faresti un esempio?
Comunque questo è il mio primo account Android :D
Grazie


Top
 Profile  
 
 Post subject: Re: Comunicazione tra emulatori
PostPosted: Thu Oct 28, 2010 5:31 pm 
Offline
Moderatore
User avatar

Joined: Thu Dec 27, 2007 3:51 pm
Posts: 986
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 1320
Sì sono sicuro che è possibile (non che sia facile..., sopratutto se i due PC della LAN sono collegati tramite un router ma ci sono anche firewall di mezzo).
Cmq, la prima cosa da fare è leggere la sezione "Emulator Networking" che trovi qui:
***URLs are hidden from guests, please register and login to view the hyperlink***
(c'è da capire cos'è il router virtuale usato dall'emulatore..)

Ecco un esempio per un emulatore che fa da Client e uno da Server su due PC diversi
Sul Server:
1) Imposta un forwarding dalla porta usata dal client (es. 8080) verso localhost:port_server.
Per far questo puoi ad esempio usare ***URLs are hidden from guests, please register and login to view the hyperlink*** specificando: Port: 8080, Destination: localhost, 5554

2) collegarsi all'emulatore tramite telnet (telnet localhost 5554) ed impostare:
redir add tcp:port:5554

3) Avviare il Server sull'emulatore

Sul Client :
1) Far partire l'emulatore che utilizza un client che si collega al PC di destinazione sulla porta 8080


Top
 Profile  
 
 Post subject: Re: Comunicazione tra emulatori
PostPosted: Fri Oct 29, 2010 12:52 pm 
Offline
User avatar

Joined: Tue Jun 08, 2010 10:55 am
Posts: 15
Punti Android: ?
Ciao Verix!
Oggi ho avuto alcuni problemi con il PC e non ho potuto provare quello che mi hai suggerito! Appena posso ti faccio sapere l'esito ;) in ogni caso grazie mille.

La redirezione delle porte la facevo, ma solo usando il comando

Code:
telnet localhost 5556
redir add tcp:8887:8080


Questo mi fa comunicare più emulatori sullo stesso PC, ma forse non è sufficiente per PC diversi!

Buon weekend :)

ps: Uso Ubuntu come SO!


Top
 Profile  
 
 Post subject: Re: Comunicazione tra emulatori
PostPosted: Wed Nov 03, 2010 1:38 pm 
Offline
User avatar

Joined: Tue Jun 08, 2010 10:55 am
Posts: 15
Punti Android: ?
Ciao Verix, ho fatto le prove che mi hai suggerito ma non ho avuto buoni risultati...probabilmente sbaglio qualcosa. Ti scrivo in dettaglio i passi:

Sul Server:
1) Usando come SO Linux, ho fatto il port forwarding mediante il comando:
Code:
> sudo iptables -A FORWARD -i eth0 -p tcp --dport 8887 -j ACCEPT
> sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 8887 -j DNAT --to 127.0.0.1:5554


2) mi sono collegata all'emulatore tramite telnet (telnet localhost 5554) ed ho impostato:
Code:
redir add tcp:8887:5554


3) Ho avviato il Server sull'emulatore:
Code:
serverSocket = new ServerSocket(5554);


Sul Client :
1) Ho avviato l'emulatore che utilizza un client che si collega al PC di destinazione sulla porta 8887
Code:
InetAddress addr = InetAddress.getByName("160.97.28.242");
socket = new Socket(addr, 8887);


Dove sbaglio???

Grazie

Deborah


Top
 Profile  
 
 Post subject: Re: Comunicazione tra emulatori
PostPosted: Wed Nov 03, 2010 3:44 pm 
Offline
Moderatore
User avatar

Joined: Thu Dec 27, 2007 3:51 pm
Posts: 986
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 1320
Ciao Deborah,
a me il setup che hai fatto sulla carta sembra tutto giusto, quindi dovrai fare un po' di debugging per capire dov'è l'intoppo....
Iniziamo dal client per vedere se sti pacchetti almeno arrivano al server:
- l'app che fa da client ha i permessi INTERNET ?
- l'apertura del socket sull'indirizzo di destinazione e sulla porta 8887 avviene regolarmente ?; verifica se viene l'anciata qualche eccezione (magari anche solo con ddms)

Se tutto sembra OK, vediamo se sul PC che fa da server arrivano i pacchetti sulla porta 8887: usando iptables prova a vedere se il contatore dei pacchetti si incrementa (non mi ricordo i comandi a memoria, ma mi sa tanto che sei più esperta di me...). In questo modo verifichi anche se i pacchetti vengono accettati e vengono forwardati sulla porta 5554.

A valle di queste verifiche, se tutto è ok, si procede per cercare di capire se i pacchetti arrivano all'APP che fa da server...
buon lavoro..


Top
 Profile  
 
 Post subject: Re: Comunicazione tra emulatori
PostPosted: Wed Nov 03, 2010 4:22 pm 
Offline
User avatar

Joined: Thu Dec 27, 2007 7:09 pm
Posts: 659
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 758
Uhm... scusate ma a me non torna una cosa: la porta 5554 è quella già utilizzata dall'emulatore che sta nel server (infatti facendo telnet localhost 5554 si accede alla console dei comandi dell'emulatore): quindi non sono sicuro che si possa usare come porta di destinazione del forwarding fatto con iptables...

Insomma, per tagliare la testa al toro, prova a fare cosi':
- il client invia i pacchetti a 160.97.28.242:8887 (tutto uguale)
- sul server:
-- i pacchetti in arrivo sulla porta 8887 vengono accettati e forwardati sulla porta localhost:8888
Code:
> sudo iptables -A FORWARD -i eth0 -p tcp --dport 8887 -j ACCEPT
> sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 8887 -j DNAT --to 127.0.0.1:8888

-- i pacchetti in arrivo sulla porta 8888 (che grazie al forwarding sono visti come provenienti dal localhost) sono reindirizzati alla porta 8080 (emulata) di ascolto dell'applicazione server tramite il comando di redir dato all'emulatore:
Code:
redir add tcp:8888:8080

-- il server è in ascolto sulla porta (emulata) 8080
Code:
serverSocket = new ServerSocket(8080);


In teoria la porta di ascolto dell'applicazione server portrebbe rimanere la 5554 perchè è quella emulata diversa da quella del server usata dall'emulatore ma propongo di cambiarla per non fare confusione... :a2: :a2: :a2: :a2:

_________________
***URLs are hidden from guests, please register and login to view the hyperlink***


Top
 Profile  
 
 Post subject: Re: Comunicazione tra emulatori
PostPosted: Thu Nov 04, 2010 11:47 am 
Offline
User avatar

Joined: Tue Jun 08, 2010 10:55 am
Posts: 15
Punti Android: ?
Grazie ad entrambi.

Barban ho usato la configurazione di porte che mi hai suggerito ma anche in questo modo gli emulatori non comunicano.

Il problema è che non si riesce a stabilire la connessione, infatti sul client viene lanciata un eccezione:

Code:
java.net.ConnectException: / 160.97.25.82:8887 - Connection refused


Non sono esperta del comando iptables infatti devo verificare che i comandi siano quelli esatti!

Sto perdendo le speranze :bang: ... ora inizio con il debugging!

Ciao :cry:


Top
 Profile  
 
 Post subject: Re: Comunicazione tra emulatori
PostPosted: Thu Nov 04, 2010 12:10 pm 
Offline
User avatar

Joined: Thu Dec 27, 2007 7:09 pm
Posts: 659
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 758
L'eccezione sul client viene lanciata dalla riga di codice
Code:
socket = new Socket(addr, 8887);
giusto?
Finchè c'è questo problema è inutile fare tanti casini con io forwarding delle porte sul server (scusa l'espressione :mrgreen: ) perchè i pacchetti non partono nemmeno...

- l'app sul client ha i permessi di accedere ad Internet ? (sul Manifest.xml ci deve essere: <uses-permission android:name="android.permission.INTERNET" />)
- prova a verificare se è il server che risponde picche facendo cosi':
sul PC dove gira l'emulatore-client, da una finestra DOS, digita:
Code:
telnet 160.97.25.82 8887

e vedi se ti dà "connection refused" (nel qual caso è un problema di rete e vediamo cosa fare... )

PS. Bella la Calabria.. ;)

_________________
***URLs are hidden from guests, please register and login to view the hyperlink***


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB SEO

All trademarks and logos used in this site are of properties of their respective owners.