Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private Socket1 As Socket
Private TimerTimeoutCom As Timer
Private RemainingTries As Short
Private Stream As AsyncSteamsText
Dim Notification1 As Notification
End Sub
Sub Service_Create
Notification1.Initialize
Notification1.Sound = False
Notification1.Icon = "icon" 'use the application icon file for the notification
Notification1.Vibrate = False
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
Sub ConnecSoccet(lHost As String, lPort As Int)
Socket1.Initialize("Socket1_Connected")
Socket1.Connect(lHost,lPort,10000)
End Sub
Sub Socket1_Connected (Successful As Boolean)
If Successful Then
Notification1.SetInfo("MyApp","Connected", Main)
Service.StartForeground(1, Notification1)
If Stream.IsInitialized Then Stream.Close
Stream.Initialize(Me,"Stream",Socket1.InputStream,Socket1.OutputStream )
Else
Service.StopForeground(1)
End If
End Sub
Sub RequestMessageFromServer
Stream.Write(" A string that ask server to send a message ")
TimerTimeoutCom.Initialize("MessageFromServerDidNotArrive",20000) '20seconds
TimerTimeoutCom.Enabled = True
End Sub
Sub Stream_NewText(Input As String)
TimerTimeoutCom.Enabled = False
'Code to handel the answer from server
End Sub
Sub MessageFromServerDidNotArrive
TimerTimeoutCom.Enabled = False
If RemainingTries > 0 Then
RemainingTries = RemainingTries - 1
RequestMessageFromServer
Else
ToastMessageShow("Could not get a message from server",True)
End If
End Sub
Sub Stream_Terminated
TimerTimeoutCom.Enabled = False
Service.StopForeground(1)
Socket1.Close
End Sub