Android Question How do I reset my ServerSocket

davepamn

Active Member
Licensed User
Longtime User
Problem: if the wifi network has a problem and the b4a tcp/ip socket does not reset then How do I reset the socket? the Pingserver does not reacquire the network after failing.

B4X:
sub Class_Globals
   dim myLan as serversocket
end sub
Sub ServerSocket1_NewConnection(Successful As Boolean, NewSocket As Socket)
End Sub

Sub PingServer As Boolean

    Dim bRetVal As Boolean=False
    If myLan.IsInitialized=False Then
        myLan.Initialize(0,"ServerSocket1")
    End If

    Dim oMLWifi As MLwifi

    If oMLWifi.isOnLine=False Then

     'Try other apis below and see if they can get past the socket problem.       

    Else

        ReturnTrue

    EndIf



    Try

        'Case 1
        Dim oPhone As Phone
        If oPhone.IsAirplaneModeOn=True Then
            bRetVal=False
            Return(bRetVal)
        End If

        Dim sDeviceIP As String
        'Check 4G connectivity
        sDeviceIP=myLan.GetMyIP
        If sDeviceIP<>"127.0.0.1" Then
            bRetVal=True
            Return(bRetVal)
        End If
        sDeviceIP=myLan.GetMyWifiIP
        If sDeviceIP<>"127.0.0.1" Then
            bRetVal=True
            Return(bRetVal)
        End If
        If oPhone.GetSettings("wifi_on")<>1 Then
            bRetVal=False
            Return(bRetVal)
        End If
        If oPhone.GetDataState="DISCONNECTED" Then
            bRetVal=True
        Else
            bRetVal=False
        End If
    Catch
        oError.ShowLastException("Error Ping")
    End Try
    Return(bRetVal)
End Sub
 
Last edited:

davepamn

Active Member
Licensed User
Longtime User
The network has a problem. My serversocket gets jammed. I can not ping the device. Once I quit the application than the socket is freed and the ping to the device works.

I need a way to reset my socket in the application.
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
when the socket jams, the tablet application "ping tools network utilities" by stream soft can not ping out. Also, I can not ping the tablet from my pc.

when I turn off the app and start it the socket becomes free. likewise if I turn the wifi off or on that the device socket becomes available.

the problems occurs at different times in the day
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
B4X:
Dim oMLWifi As MLwifi
    If iWifiVarOnCount<10 Then
        If oMLWifi.isOnLine=False Then
            oMLWifi.EnableWifi(False)
            oMLWifi.EnableWifi(True)
            iWifiVarOnCount=iWifiVarOnCount+1
        End If
    End If


This code kept my device available for ping after 16 hours of run time. However, myLan.GetMyWifiIP does not get the ipaddress.

where myLan as ServerSocket
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
Can I have two asychronous streams running, one per service? do you think the streams are causing the socket to plug
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
do you think there is a bug with the samsung tablet 2 using wifi locking up after a certain number of hours of usage?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use as many AsyncStreams as you need. They can be in the same service or different services.

In the UI Cloud there are 10 devices that run for months doing many network communication. To avoid all kinds of problems, as Android devices are not 100% stable, the app is killed every several hours and then started again (automatically).
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I have a Samsung phone which becames almost unusable after about 24 hours on. To use it I must restart and after restarting it downloads up to 5 APP updates from Google Play. I have reset it, reloaded firmware and the bug showed again in 3 days! Samsung was not able to fix it.
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
I moved all my httpjob and job done code out of a class into a form and the application did not freeze up. I have had problems putting httpjob in a class and not receiving a handle job call back. Will you try putting a httpjob with at least 20 parameters into a class and run it for 24 hours and see if your app freeze up?
 
Upvote 0
Top