Hi,
I have developed a couple small inter-process comms app to enable starting and stopping of headless b4j programs.
There is a server that has a UI. This is used to control the other process.
The server is the process to be controlled. In this example it has a UI, but it normally wouldn't
If I keep everything in the clients Main program it works fine. But if I put the socket functions in a class it compiles OK, runs OK except that when ir responds to astream.Reads using the serialisation of a custom type, it throws errors both in the client and server.
Part of the Client side ipcComms class is shown below
I have attached the programs as zips. The
InterProcessCommsLocalHostClientUsingClass.zip => is the class version of the client that fails
InterProcessCommsLocalHost.zip => is the server and client that works
I wish to make the client as a class so I can use this class in headless programs to be controlled by the server app.
I also tried using a code module, but got the same error.
Can anyone help?
Best regards
Rob
I have developed a couple small inter-process comms app to enable starting and stopping of headless b4j programs.
There is a server that has a UI. This is used to control the other process.
The server is the process to be controlled. In this example it has a UI, but it normally wouldn't
If I keep everything in the clients Main program it works fine. But if I put the socket functions in a class it compiles OK, runs OK except that when ir responds to astream.Reads using the serialisation of a custom type, it throws errors both in the client and server.
Error on Client Side:
Waiting for debugger to connect...
Program started.
Error occurred on line: 63 (ipcComms)
java.lang.RuntimeException: java.lang.ClassNotFoundException: b4j.example.b4xmainpage$_cmddata_t
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:314)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:374)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:129)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertBytesToObject(B4XSerializator.java:99)
at b4j.example.ipccomms._astream_newdata(ipccomms.java:228)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$2.run(BA.java:230)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: b4j.example.b4xmainpage$_cmddata_t
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readTypeClass(RandomAccessFile.java:546)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:291)
... 25 more
Part of the Client side ipcComms class is shown below
IPC Comms Class:
Sub Class_Globals
Private fx As JFX
Type cmdData_t (cmd As Int, _
cmdName As String, _
dt As Long, _
status As Int, _
jDate As Double, _
Vrms As Double, _
Freq As Double)
Private Const PAUSE_I As Int = 0
Private Const RUN_I As Int = 1
Private Const CHEKPOINT_I As Int = 2
Private Const SHUTDOWN_I As Int = 3
Private Const GET_DATA_I As Int = 4
Private Const PAUSE_S As String = "Pause"
Private Const RUN_S As String = "Run"
Private Const CHEKPOINT_S As String = "Checkpoint"
Private Const SHUTDOWN_S As String = "Shutdown"
Private Const GET_DATA_S As String = "GetData"
Private Const STATUS_OK As Int = 0
Private Const STATUS_ERROR As Int = 1
Private cmdWrite As cmdData_t
Private cmdRead As cmdData_t
Private Astream As AsyncStreams
Public IsConnected As Boolean
Private ser As B4XSerializator
Private socket As Socket
Private tmr As Timer
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
cmdRead.Initialize
cmdWrite.Initialize
tmr.Initialize("tmr", 2000)
tmr.Enabled = True
SetState(False)
End Sub
'============================================================================================
Private Sub SetState(connected As Boolean)
IsConnected = connected
If IsConnected Then
' lblState.Text = "State: Connected"
Else
' lblState.Text = "State: Disconnected"
End If
End Sub
'============================================================================================
Private Sub Astream_NewData(buffer() As Byte)
' Try
cmdRead = ser.ConvertBytesToObject(buffer) 'Error here'
' Catch
Log(LastException)
' End Try
Log(("Read Data: " & cmdRead.cmd & " - " & cmdRead.cmdName & "Status: " & cmdRead.status & " Date: " & cmdRead.dt))
'Debug only
cmdWrite.cmd = cmdRead.cmd
cmdWrite.cmdName = cmdRead.cmdName
cmdWrite.status = STATUS_OK
cmdWrite.dt = DateTime.Now
'------------------------------
Select cmdRead.cmd
Case PAUSE_I
Case RUN_I
Case CHEKPOINT_I
Case SHUTDOWN_I
'Check point db
'Setup return message
astreamWriteData
'Exit app
ExitApplication
Case GET_DATA_I
End Select
astreamWriteData
End Sub
'============================================================================================
Private Sub astreamWriteData
Astream.Write(ser.ConvertObjectToBytes(cmdWrite))
Log(("Write Data: " & cmdWrite.cmd & " - " & cmdWrite.cmdName & "Status: " & cmdWrite.status & " Date: " & cmdWrite.dt))
End Sub
I have attached the programs as zips. The
InterProcessCommsLocalHostClientUsingClass.zip => is the class version of the client that fails
InterProcessCommsLocalHost.zip => is the server and client that works
I wish to make the client as a class so I can use this class in headless programs to be controlled by the server app.
I also tried using a code module, but got the same error.
Can anyone help?
Best regards
Rob