B4J Question Incorporating B4XSerialization to non ui app

warayTek

Member
Licensed User
I have a running app with the following setup.

Image sender:
B4A - appication that capture image
Image receiver
B4J - application UI receices image from B4A

Now I need to convert the B4J app to a non-ui

This is what I have .

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Public ServerIP As String
    Private connected,flag1 As Boolean
    Private client As Socket
    Public server As ServerSocket
    Private astream As AsyncStreams
    Private const PORT As Int = 51043
    Private working As Boolean = True
    Private ser As B4XSerializator
    Type DBResult (Tag As Object, Columns As Map, Rows As List)
    Type DBCommand (Name As String, Parameters() As Object)
    Public rdcLink As String
    Dim mcateg,mvalue,qrfilename,queryResults As String
    Type MyMessage (infodetails As String, Image() As Byte,status As String)
End Sub

Sub AppStart (Args() As String)
    connected = False
    Log("System start...")
    server.Initialize(PORT, "server")
    ListenForConnections
    If File.Exists("C:\BusinessPhotoGrabber","") Then
        Log("file found")
    Else
        Log("file Not found...creating folders")
    End If
End Sub

Private Sub ListenForConnections
    Do While working
        server.Listen
        Wait For Server_NewConnection (Successful As Boolean, NewSocket As Socket)
        If Successful Then
            CloseExistingConnection
            client = NewSocket
            astream.InitializePrefix(client.InputStream, False, client.OutputStream, "astream")
            UpdateState(True)
           
        End If
    Loop
End Sub

Sub CloseExistingConnection
    If astream.IsInitialized Then astream.Close
    If client.IsInitialized Then client.Close
    UpdateState (False)
End Sub

Sub AStream_Error
    UpdateState(False)
End Sub

Sub AStream_Terminated
    UpdateState(False)
End Sub

Sub UpdateState (NewState As Boolean)
    connected = NewState
    If connected Then
        Log("Connected!")
               
    Else
        Log("Connected!")
       
    End If
    flag1 = True
    ServerIP =  server.GetMyIP
   
End Sub


Public Sub SendData (data() As Byte)
    If connected Then astream.Write(data)
End Sub


Sub AStream_NewData (Buffer() As Byte)
    Dim mm As MyMessage = ser.ConvertBytesToObject(Buffer)
    Log(mm.infodetails)
    Dim dataValue() As String
    dataValue = Regex.Split(",",mm.infodetails)
    Log(dataValue(0) & " " & dataValue(1))
    Dim accntNo,appId,imageFile As String
    accntNo =  dataValue(1)
    appId =  dataValue(2)
    imageFile = dataValue(3)
    If mm.infodetails.Contains("portal") And accntNo.Length> 1 Then
        Log("Get the information: " & accntNo)
    End If
   
   
    If mm.infodetails.Contains("image") And appId.Length> 0 Then
        If mm.Image.Length > 0 Then
            Log("has image")  
            Dim bmp As B4XBitmap = LoadBitmapFromBytes(mm.Image)
            Dim DirUserDefaultReM As String = "\\10.0.27.194\FileAttachment\Folder_DIR\" & accntNo
            Dim DirUserDefault As String = "C:\BusinessPhotoGrabber"
            Dim mFile As String
            mFile = accntNo & "_" & imageFile
            Log(mFile)
            Dim out As OutputStream = File.OpenOutput(DirUserDefault, mFile, True)
            bmp.WriteToStream(out, 100, "PNG")
            out.Close
       
        End If

        Log(mcateg)
        Log("Process done!")
    End If
End Sub

Private Sub LoadBitmapFromBytes(Data() As Byte) As B4XBitmap
    Dim in As InputStream
    in.InitializeFromBytesArray(Data, 0, Data.Length)
    #if B4J
    Dim bmp As B4XImageView
    #Else If B4A or B4i
    Dim bmp As Bitmap
    #End If
    bmp.Initialize2(in)
    Return bmp
End Sub

The above codes is not compiling due to this error.
DoneScreenshot 2025-01-16 095347.png

I attached the sample project.

I appreciate any help.
 

Attachments

  • photoGrabberNUI.rar
    15.9 KB · Views: 17

William Lancee

Well-Known Member
Licensed User
Longtime User
The error is because labels are not possible in nonGUI.
I looked for any views in your code, but I didn't see the use of a view.
However, the code you posted isn't everything (line 30 as the error for example - AnimatedCounter is part of a GUI View)
It isn't B4XSerializer, see below
So I encourage you to look for the use of a view in one of your classes.

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Dim serializer As B4XSerializator
    Dim AlbumFiles As Map = serializer.ConvertBytesToObject(File.ReadBytes(File.DirAssets, "AlbumFiles.txt"))
    Log(AlbumFiles.Size)
'    Hello world!!!
'    495
'NO ERRORS
End Sub
 
Upvote 0
Top