Android Question Wifi for several connections

postasat

Active Member
Licensed User
Longtime User
Hello guys,

I need to exchange data (not file, only text messages) between one and several android device.

I have one android tablet and I need that act as a wifi server (without AP) to receive simple messages from every phone (client) connected in wifi to the tablet.

Is it possible ? Which is the limit number for client phones connected at the same time ?
How can I do ?

Thank you.
 

postasat

Active Member
Licensed User
Longtime User
Hi Erel,

the best would be to create a wireless network where the tablet is the server (hotspot ?) without external wireless network.
To have the tablet and the phones connected together also in place where there is not a wireless network available.
If this is not possible, I could still use the same wireless network for all the devices (tablet and phones).

I'm using serial bluetooth (perfect !), but now I need to have a connection with more than 7 devices at the same time to send message from phones to tablet and I don't know how to find a solution.

Thank you.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are two separate issues here:
1. Creating a local network.
2. Implementing the application level communication.

For the first one you will need to create a hotspot. Any device can create the hotspot. It doesn't need to be the server.

I recommend you to use MQTT for the communication. You can run the broker on the server (or any other device). This is the simplest way to communicate between multiple devices.
 
Upvote 0

postasat

Active Member
Licensed User
Longtime User
Hello Erel,
thank you for your solution, it seems perfect.

I installed the jMQTT library and jMqttBroker library.
I downloaded MQTT Chat Room example.
I added only this code in manifest editor (but without I have the same error)
B4X:
AddPermission(android.permission.INTERNET)

I have this error during compile:

B4A version: 6.00
Parsing code. (0.02s)
Compiling code. (0.45s)
Compiling layouts code. (0.04s)
Organizing libraries. (0.02s)
Generating R file. (0.64s)
Compiling generated Java code. (5.34s)
Convert byte code - optimized dex. Error
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.log4j.chainsaw.ControlPanel$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/eclipse/moquette/server/ConfigurationParser;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:615)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:570)
at com.android.dx.command.dexer.Main.access$2(Main.java:546)
at com.android.dx.command.dexer.Main$2.processFileBytes(Main.java:514)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:537)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:449)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:236)
at com.android.dx.command.dexer.Main.run(Main.java:206)
at com.android.dx.command.dexer.Main.main(Main.java:179)
at com.android.dx.command.Main.main(Main.java:103)
1 error; aborting

Did I miss something ?
 
Upvote 0

postasat

Active Member
Licensed User
Longtime User
Hi Erel,

thank you now is fixed, I can compile.
I tried the example installing on a tablet (only with wifi) and in a phone.
I create an hotspot on a tablet and I have connected correctly the phone to the tablet wifi network.
When I setup the app in the tablet to be the server, the address is always 127.0.0.1, with the phone set as client I can't connect to this address.
If I use the tablet connected to my home wifi and create an hotspot on the tablet now the address is 192.... and with the phone I can connect and exchange messages.
Is it possible to change the address on the tablet not to be a localhost 127.0.0.1 also if the tablet is not connected to an external network ?
It will be perfect if I could use it creating a network with the tablet without connection to external wifi or data network.

Thank you.
 
Upvote 0
Top