B4J Question java.net.SocketTimeoutException: Read timed out

woniol

Active Member
Licensed User
Hi,
I use Socket library do read data from my alarm system.
I open socket connection and continously write command and read answer.

From time to time i get this in the log and the class that is used for this communication freezes.
I mean, I have w timer to check if socket is connected that fires every 5 seconds. After this exception timer ticks are not fired, but after some some they get fired 1 by 1 with 5 ms period.

Here's the log msg:
B4X:
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at java.net.SocketInputStream.read(SocketInputStream.java:107)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:184)
    at java.lang.Thread.run(Thread.java:744)
Is it possible to Try/Catch this exception?

Shall I close and open the socket every time i write new command?
 

woniol

Active Member
Licensed User
How are you creating the sockets?
This is my connect sub:
B4X:
Sub Connect
    Main.AppLog("Satel:: Connecting..."&IP&":3000 ")
    If client.Connected = False Then
        client.Initialize("client")
        Try
            client.Connect(IP, Port, 3000)
            client.TimeOut = 10000
        Catch
            Main.AppLog("Satel:: Connection problem: "&LastException.Message)
        End Try
    End If
End Sub
Is it possible that:
B4X:
client.TimeOut = 10000
is causing this exception?
 

woniol

Active Member
Licensed User
Ok, I will give it a try without setting this property.
Thank You.
 
Last edited:

woniol

Active Member
Licensed User
Hi,
After some tests i turned out that form time the anses from alarm systme is delaye or even not generated.
Would it be possible to turn the timeout and handle Read timed out exception that is thrown?
 
Top