Android Question Multiple Sockets B4A

MartinM

New Member
I have a small project that has to output to two different IPs at the same time if possible,
I have one up and running ok but can’t seem to register a second Socket.
Does anyone have any pointers.

thanks in advance
Martin
 

DonManfred

Expert
Licensed User
Longtime User
Does anyone have any pointers.
How can anyone help here? You are providing zero information about what you are doing and how.

Post the relevant code, Upload a small project showing the problem.

At least you need to use different Asyncstreams for each of the IPs you want to work with.
 
Last edited:
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I have a small project that has to output to two different IPs at the same time if possible,
I have one up and running ok but can’t seem to register a second Socket.
Does anyone have any pointers.

thanks in advance
Martin

What I have learned for things like this, is to declare/define everything related to a single socket into a Class. then initialize multiple instances of that class for each and every socket you need with the appropriate callbacks as needed. That typically works.

This allows each class to be mutually exclusive to one another but also tie back to a common point. So treat the socket and its methods/functions related to that socket as its own object instance.

In my case, I needed/use multiple MQTT client listeners that basically do the same thing, just monitor different subtopics for different IDs. So, i just put all the code in a single class, and initialized that same class into an array with different initialization data for each one. It worked fine.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
MQTT is indeed an excellent solution.

Two examples that support multiple connections:
[B4X] FTP Server implemented with Socket and AsyncStreams
 
Upvote 0
Top