B4J Question JRDC Error handling

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I use jRdc2 a lot, but I cannot figure out how to trap errors when the jRDC server isn't running and I make a client request. When I get such an error it crashes the program.

Has anyone done this or has anyone written code that can check to see if the jRDC is available on the connection string and port?

Regards
Rob
 

josejad

Expert
Licensed User
Longtime User
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
A slightly different alternative to @José J. Aguilar answer.
How about using the test handler that's included in the the jRDC2 download) :
Check RDC Status:
Private Sub CheckRDCStatus As ResumableSub

    Dim j As HttpJob
    j.Initialize("", Me)
    j.GetRequest.Timeout = 10000
    j.Download($"http://${rdcPath}:${rdcPort}/test"$)
    Wait For (j) JobDone(j As HttpJob)
    Dim success As Boolean = j.Success
    If success Then
        
        Log(j.GetString)
        
    Else
        Log("Connection failed")
        Log(j.ErrorMessage))
    End If
    j.Release

    Return success

End Sub

If all is well, j.GetString should return something like:
B4X:
RemoteServer is running (2023-03-08 09:32:57)
Connection successful.
The second line confirming a successful database connection as well.
 
Upvote 1

Chris2

Active Member
Licensed User
Longtime User
When I get such an error it crashes the program
Are you trying to handle returned data without checking j.success first?
Can you post the code you're using to send commands to the server? And the error message when the client crashes?
 
Last edited:
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
Hi All,
Thanks for your help.

I ended up doing this:

Test For RDC:
'============================================================================================
Public Sub Testconnection(ipaddr As String, port As Int, timeout As Int)As ResumableSub
    Dim testSocket As Socket
    
    ConnStatus = False
        
    If testSocket.IsInitialized = False Then
        testSocket.Initialize("ipc_socket")
        testSocket.Connect(ipaddr, port, timeout)
    End If
        
    Try
        Log("Connect to Server - Wait for Connection")
        Wait for ipc_socket_Connected(Successful As Boolean)
        Log("Connect to Server - Socket Connected")
    Catch
        Log("Connect to Server - Socket try failed")
    End Try
        
    If Successful Then
        Log("Connect to Server - Socket Found")
    
        ConnStatus = True
        testSocket.Close
        Return True
    End If
    Log("Connect to Server - Socket Not Found")
    ConnStatus = False
    Return False
End Sub

Regards
Rob
 
Upvote 0
Top