Android Question Send text over Wifi to many clients

MolsonB

Member
Licensed User
Longtime User
Going off the walkie talkie example using server & socket, how can you have multiple clients sockets attached to one server over wifi hotspot?

I have a microcomputer processing sensors and sending the data out over bluetooth. The main tablet program connects to the bluetooth and reads the sensors. Opens up a wifi hotspot and passes the data onto who ever is attached to that hotspot. I have it working with 1 client, but when I connect another client, it boots off the first one.

Can the serversocket and socket only handle 1 for 1 connection? How else would I broadcast data over wifi to any number of clients attached? Would I use TCP instead and use 255.255.255.0 ?
 

MolsonB

Member
Licensed User
Longtime User
I'm also looking at the HttpServerChat program you created aswell. So it looks like I should look into HttpServer & HttpJob instead of Socket & AsyncStreams. I liked using async as it would fire when new data arrived. With the http, I'll have to use a timer and keep on looping. Checking if the data is stale incase the server stopped. Seems like a lot more overhead with http then with async.
 
Upvote 0

MolsonB

Member
Licensed User
Longtime User
HttpServer & HttpJob, I have the server starting a wifi hotspot and opening up a http port. The clients will connect to the hotspot and search for the open ports.

This works great with devices that don't have any mobile cell data connection. When I try to use my cellphone, since the hotspot doesn't have 'internet' access, it gives it limit connection status and uses the cell data network instead. I lose my ability to connect to the local httpserver hotspot ipaddress (192.168.43.1). As soon as I disable mobile data, the cell phone is forced to use the wifi connection and connects to the httpserver.

Now I don't want to 'turn' off mobile data when I run the program, I still want to receive calls and texts while the program is running on my cell phone. But is there a way to force using the wifi connection even though there is no internet on it? When the program is paused, it can go back to using mobile data. On resume, force to use wifi.

*edit. Doing more reading, it looks like depending on what a Android version you have will act differently. Early versions would only let you connect to either WiFi or mobile. In lollipop, you can connect to WiFi (with no internet) and still get internet over mobile.

ConnectivityManager looks to be the answer.
https://developer.android.com/about/versions/android-5.0.html#Wireless
 
Last edited:
Upvote 0
Top