Erel! I wrongly posted this on B4A forum,can you remove that thread,I don't know if I can do that.
I made a small B4j app launced by a bat-file from a Pc prog for communicate to a Raspberry pi and it works ok. It consumes some time though to launch the B4j app everytime a msg is to be sent (every 5-10 secs). To speed up things I want the app to be launched just once.Is there a way to make a B4j app to listen for incomming commands (like vb6 'command$') ? I have not find info about this on forum.
Any tips on how to optimize code below also welcome!
Regards Håkan
I made a small B4j app launced by a bat-file from a Pc prog for communicate to a Raspberry pi and it works ok. It consumes some time though to launch the B4j app everytime a msg is to be sent (every 5-10 secs). To speed up things I want the app to be launched just once.Is there a way to make a B4j app to listen for incomming commands (like vb6 'command$') ? I have not find info about this on forum.
Any tips on how to optimize code below also welcome!
B4X:
'Non-UI application (console application)
#Region Project Attributes
' #CommandLineArgs: TEST
#End Region
Sub Process_Globals
Dim TcpStreams As AsyncStreams
Dim Socket1 As Socket
Dim StringToSend As String
End Sub
Sub AppStart (Args() As String)
If Args.Length = 0 Then
Log("Arguments missing")
ExitApplication2(1)
End If
'socket for connecting to 'Raspberry Pi-gateway on port 32340
Socket1.Initialize("Socket1")
Socket1.Connect("192.168.1.4",32340,5000)
StringToSend = Args(0)
StartMessageLoop
End Sub
Sub Socket1_Connected(Connected As Boolean)As Boolean
If Connected = True Then
TcpStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"tcpStreams")
Try
SendData(StringToSend)
Catch
Log("Send Error")
End Try
End If
End Sub
Sub SendData(Msg As String)'to Pi Gateway (port 32340)
Dim Buffer() As Byte
If Socket1.Connected = True Then
Try
Buffer = Msg.GetBytes("UTF8")
TcpStreams.Write(Buffer)
Log("Data sent")
ExitApplication2(1)
Catch
Log("TcpStreams.Write Error")
End Try
Else
Log("Connection lost")
End If
End Sub