B4J Question B4J Objectsent event not raised

HARRY

Active Member
Licensed User
Longtime User
Hi,
Environment: B4J 5.80 relevant librarry: jRandomAccessFile(Verion 2.30)

I am trying to send an image file to my Android Phone:
Parts of the code:
B4X:
Dim Stream3 As AsyncStreams        'image to smart phone
Dim Server3 As ServerSocket        'belongs to Stream3

In AppStart

If Server3.IsInitialized=False Then Server3.Initialize(42000,"Server3")


Sub Server3_NewConnection (Successful As Boolean, NewSocket As Socket)  'Wifi or internet used for sending image
    If Successful Then
        Stream3.InitializePrefix(NewSocket.InputStream, False,NewSocket.OutputStream,"Stream3")
    Else
        Log ("Server 3 connection error" & LastException.Message)
    End If
    Server3.Listen
End Sub

Sub SendFile (nrimage As Int)
    If File.Exists("/home/pi/MyApps/Domo/Images","Webcam" & nrimage & ".jpg")  Then
        Dim bmpData() As Byte =Bit.InputStreamToBytes(File.OpenInput("/home/pi/MyApps/Domo/Images","Webcam" & nrimage & ".jpg"))
        Dim dataToSend() As Byte = ser.ConvertObjectToBytes(CreateMap("FileName": "Webcam", "Data": bmpData))
        Log("Sending")
        Stream3.Write(dataToSend)
    Else
        mcode=18
        Stream2.Write(mcode & s & imagenr & s & CRLF)  'gives an error code to the phone
    End If
End Sub

Sub Stream3_ObjectSent (Key As String)
    Dim jo1 As JavaObject
    Dim jo2 As JavaObject
    Log("sending complete")
    If camrequest=True Then   'reorganize the image files
        If File.Exists("/home/pi/MyApps/Domo/Images","Webcam" & "19" & ".jpg") = True Then
            File.Delete("/home/pi/MyApps/Domo/Images","Webcam" & "19" & ".jpg")
            Log("Nr 19 removed")
        End If
        For i=18 To 0 Step-1
            If File.Exists("/home/pi/MyApps/Domo/Images","Webcam" & i & ".jpg") = True Then
                jo1.InitializeNewInstance("java.io.File",Array("/home/pi/MyApps/Domo/Images/Webcam" & i & ".jpg"))
                jo2.InitializeNewInstance("java.io.File",Array("/home/pi/MyApps/Domo/Images/Webcam" & (i+1) & ".jpg"))
                jo1.RunMethod("renameTo",Array(jo2))
                Log(i & " removed")
            End If
        Next
        If File.Exists("/home/pi/MyApps/Domo/Images","Webcam" & "99" & ".jpg") = True Then
            jo1.InitializeNewInstance("java.io.File",Array("/home/pi/MyApps/Domo/Images/Webcam" & "99" & ".jpg"))
            jo2.InitializeNewInstance("java.io.File",Array("/home/pi/MyApps/Domo/Images/Webcam" & "0" & ".jpg"))
            jo1.RunMethod("renameTo",Array(jo2))
            Log(99 & " renamed")
        End If
        camrequest=False
    End If   
End Sub

Following the log messages, the latter sub is never entered.

I cannot find why?

Any idea?

Harry
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…