Android Question Send text over Wifi to many clients

Discussion in 'Android Questions' started by MolsonB, May 7, 2015.

  1. MolsonB

    MolsonB Member Licensed 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 ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Each socket can handle a single connection. However you can create as many sockets as you need.

    I recommend you to go over the CCTV example (written with B4J) which can handle any number of connections. Go over the example in the second post.
     
  3. MolsonB

    MolsonB Member Licensed 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.
     
  4. MolsonB

    MolsonB Member Licensed 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: May 14, 2015
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice