Android Question Response Error while connecting with okhttputils2

Pravee7094

Active Member
Hello All,

Response Error came while run the program. I write a just simple connection program. Here is the code.
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Dim strURL As String = "http://192.xxx.x.xx:8080/loginphp/"
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private lblUsername As Label
    Private lblPassword As Label
    Private edtUsername As EditText
    Private edtPassword As EditText
    Private btnSubmit As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("login")
    TestConnection
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub TestConnection
Dim Connect As HttpJob
    Connect.Initialize("Connect", Me)
    Connect.Download(strURL & "connection.php")
    ProgressDialogShow("Connecting...")
End Sub

Sub JobDone (Job As HttpJob)
    ProgressDialogHide
    If Job.Success = True Then
        Dim ret As String
        ret = Job.GetString
        Dim parser As JSONParser
        parser.Initialize(ret)
        If Job.JobName = "Connect" Then
            Dim act As String = parser.NextValue
            If act = "ConnectionSuccessful" Then
                ToastMessageShow("Connection success", True)
            End If
        End If
    Else
        Log("failure")
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Sub btnSubmit_Click
    
End Sub

This is Php code
PHP:
<?php
    print json_encode("ConnectionSuccessful");
?>

Error message I have:

ResponseError. Reason: java.net.SocketTimeoutException: failed to connect to /192.XXX.X.XX (port 8080) from /192.XXX.X.XX (port 36126) after 30000ms, Response:

Anybody Help!

Thanks
 

Pravee7094

Active Member
You should learn how to use Wait For: https://www.b4x.com/android/forum/threads/79345/#content

Make sure that the relevant port it open in Windows firewall.
Hello sir,

I saw that video above you mentioned. Thats greatful. But still I have a doubt.

I run the codings in local server. The question is, How the PHP code is running? For example when we work with JRDC2, we have a B4J project, so thats run on the server side.
But When we work with php and mysql using okhttputils2 how the process is going? How the php file running on server side?

Any suggestions

Regards
 
Upvote 0
Top