Socket issue

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I am having some issues with a socket when swapping connections between 3G and Wi-Fi.

Lets say I am connected using 3G to a TCP/IP device and sending data. Everything is working fine.

You press the Home button on your device (so the app is paused in the background)

You turn on the Wi-Fi, so the 3G is no longer used as its now using the Wi-Fi for your data connection.

You re-open the app again (app is now un-paused) then try and send a command to the TCP/IP device, it doesn't work as you have closed the 3G connection and now connecting by Wi-Fi.

So my question is how do you tell the app to drop the connection and re-connect again to the TCP/IP device when the 3G or Wi-Fi has changed ?
 

aaronk

Well-Known Member
Licensed User
Longtime User
I have now made it so that when the app is paused (or the Home button is pressed) to close/finish the activity.

Now the next issue is that if you leave the app open, and change the connection from 3G to Wi-Fi (or even turn Wi-Fi on then back off again) the socket will not send data as it looses connection.

How can I make it so that my app will re-connect automatically again when the user changes the connection when the app is left open ?
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Why do you need to keep the connection open all the time?

There isn't really any reason.

I guess I should add (which I forgot that part in my code):

B4X:
Sub Activity_Pause(UserClosed As Boolean)
    If UserClosed Then
        Log("closing")
        AStreams.Close
        Socket1.Close
    End If
End Sub

Are you using AsyncStreams?

Yes I am as per your AsyncStreams Tutorial

I seem of fixed the issue when they leave the app and then re-open the app again it will now re-connect.

But if they connect to a device (lets say using 3G) and then change there connection (to lets say Wi-Fi) while the app is open and visible on the screen, then send data to the device it will not send as there is no connection anymore and they need to re-connect again using the Wi-Fi.

I need to somehow make it reconnect once the app knows it's lost connection and try and connect using the new method (either Wi-Fi or 3G) based on what is available (enabled) on the device at the time of re-connecting.
 
Upvote 0
Top