I am communicating with an IoT device in which I open a TCP connection, send some text, and a second later, get a string response from the IoT device.
I have VB6 code that works fine:
Which results in this immediate window (debug) output:
As you can see the IoT device returns the string of "completeir,1:3,1"
So, I am now trying to implement this in B4A with this code:
But when I run this code, it sends the command to the IoT properly, but then there is a 30 second delay and then I get a timeout error:
My guess is that when the IoT device returns a string, it's just a simple string and not in an HTTP response format (that would include a proper status code like "200"), which the HTTPJob is waiting for. And when such a code never arrives, it eventually times out and throws an error.
So, how can I receive the IoT text response right away without a timeout error?
I have VB6 code that works fine:
B4X:
Private Sub cmdSend_Click()
sock.Protocol = sckTCPProtocol
sock.RemoteHost = "192.168.1.170"
sock.RemotePort = 11000
sock.Connect
End Sub
Private Sub sock_ConnectionRequest(ByVal requestID As Long)
Debug.Print "Sock Conn Request: " & CStr(requestID)
sock.Accept
End Sub
Private Sub sock_Connect()
Debug.Print "Sock Connect...Sending Command..."
sock.SendData ("sendir,1:3,1,38000,1,69,342,171,21,63,21,21,21,63,21,21,21,21,21,21,21,21,21,63,21,21,21,21,21,21,21,21,21,63,21,63,21,21,21,21,21,21,21,63,21,63,21,21,21,63,21,63,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,63,21,63,21,1753,342,85,21,3645" & Chr(13))
End Sub
Private Sub sock_SendComplete()
Debug.Print "Send Complete"
End Sub
Private Sub sock_DataArrival(ByVal bytesTotal As Long)
Dim T As String
Call sock.GetData(T, , bytesTotal)
Debug.Print "Sock_DataArrival: " & T
sock.Close
End Sub
Private Sub sock_Close()
Debug.Print "Sock_Close"
End Sub
Private Sub sock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Debug.Print "Sock_Error: " & Description
End Sub
Which results in this immediate window (debug) output:
B4X:
Sock Connect...Sending Command...
Send Complete
Sock_DataArrival: completeir,1:3,1
As you can see the IoT device returns the string of "completeir,1:3,1"
So, I am now trying to implement this in B4A with this code:
B4X:
Sub cmdTest_Click
Dim j As HttpJob
Dim Cmd As String
j.Initialize("",Me)
Cmd = "sendir,1:3,1,38000,1,69,342,171,21,63,21,21,21,63,21,21,21,21,21,21,21,21,21,63,21,21,21,21,21,21,21,21,21,63,21,63,21,21,21,21,21,21,21,63,21,63,21,21,21,63,21,63,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,63,21,63,21,1753,342,85,21,3645" & Chr(13)
Log("Sending IR.....")
j.PostString("192.168.1.170:11000", Cmd)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log("Job_OK: " & j.GetString)
Else
Log("Job_Error: " & j.ErrorMessage)
End If
j.Release
End Sub
But when I run this code, it sends the command to the IoT properly, but then there is a 30 second delay and then I get a timeout error:
B4X:
** Activity (main) Resume **
Sending IR.....
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ResponseError. Reason: java.net.SocketTimeoutException, Response:
Job_Error: java.net.SocketTimeoutException
My guess is that when the IoT device returns a string, it's just a simple string and not in an HTTP response format (that would include a proper status code like "200"), which the HTTPJob is waiting for. And when such a code never arrives, it eventually times out and throws an error.
So, how can I receive the IoT text response right away without a timeout error?