My goal is to establish peer-to-peer connection between two android devices. To achieve this goal, I chose the protocol mqtt. I would like to start the broker on the first device, and the second one to connect to the first one. I create a broker in this way:
I added these dependencies to the gradle
dependencies {
compile 'io.moquette:moquette-netty-parser:0.8.1'
compile 'io.moquette:moquette-broker:0.8.1'
compile 'io.moquette:moquette-parser-commons:0.8.1'}
Then created a server, but the default URI is tcp://localhost:1883 so the second device I can connect to this broker only if both devices are connected to the same wi-fi point.
broker = new Server();
try {
MemoryConfig memoryConfig = new MemoryConfig(new Properties());
memoryConfig.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME,
Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator
+ BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME);
broker.startServer(memoryConfig);
} catch (IOException e) {
e.printStackTrace();
}
And I Use Paho libraries for android
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
I would like to be able to connect to the broker even if the devices are connected to different points of wi-fi or use 3G/4G.
I honestly tried to find a solution for several days, but I did not succeed. I really do not know how to achieve this. Therefore, I have two questions. Is it possible that I want to do? And How?