#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private server As ServerSocket
Private astream As AsyncStreams
Public IsConnected As Boolean
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
ListenForConnections
End Sub
private Sub SetState (connected As Boolean)
IsConnected=connected
CallSub(Main,"StateChanged")
End Sub
private Sub ListenForConnections
server.Initialize(1024,"server")
Log($"my IP is : ${server.GetMyWifiIP}"$)
server.Listen
Wait For server_NewConnection(Successful As Boolean, NewSocket As Socket)
Log("New connection")
If Successful Then
If astream.IsInitialized Then
astream.Close
End If
astream.Initialize(NewSocket.InputStream,NewSocket.OutputStream,"astream")
SetState(True)
End If
End Sub
private Sub astream_NewData (Buffer() As Byte)
End Sub
private Sub astream_Terminated
SetState(False)
End Sub
private Sub astream_Error
astream_Terminated
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub