'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim IPofThisDevice, IPofTheOtherDevice As String
Dim portOfThisDevice, portOfTheOtherDevice As Int
Dim aNewSocket As Socket
Dim tmr2 As Timer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ips(2) As String
Dim ports(2) As Int
ips(0)="192.168.1.5"
ips(1)="192.168.1.20"
ports(0)=5010
ports(1)=5011
Dim btn1, btn2, btn3 As Button
Dim lbl1, lbl2 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
btn1.Initialize ("btn1")
btn1.Text="Start Service"
Activity.AddView (btn1,0,0,Activity.Width /2,100dip)
btn2.Initialize ("btn2")
btn2.Text="Stop Service"
Activity.AddView (btn2,0,100dip,Activity.Width /2,100dip)
btn3.Initialize ("btn3")
btn3.Text="Ping"
Activity.AddView (btn3,0,200dip,Activity.Width /2,100dip)
Dim res As Int
Dim lst As List
lst.Initialize
lst.AddAll (Array As Int(1,2))
res=InputList(lst,"Please select device (1 or 2)",0)
If res>-1 Then
IPofThisDevice=ips(res):portOfThisDevice=ports(res)
res=1-res
IPofTheOtherDevice=ips(res):portOfTheOtherDevice=ports(res)
End If
lbl1.Initialize ("")
lbl1.Text="this dev:" & IPofThisDevice & ":" & portOfThisDevice
Activity.Addview(lbl1,0,300dip,Activity.Width ,100dip)
lbl2.Initialize ("")
lbl2.Text="other dev:" & IPofTheOtherDevice & ":" & portOfTheOtherDevice
Activity.Addview(lbl2,0,400dip,Activity.Width ,100dip)
tmr2.Initialize ("tmr2",2000)
tmr2.Enabled =False
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btn1_click
StopService(ourserver)
StartService(ourserver)
End Sub
Sub btn2_click
StopService(ourserver)
End Sub
Sub btn3_click
pingTheOtherDevice
End Sub
Sub pingTheOtherDevice
' just a ping test
closeStreamsIfOpen
aNewSocket.Initialize ("SocketPing")
aNewSocket.Connect (IPofTheOtherDevice,portOfTheOtherDevice,20)
End Sub
Sub SocketPing_connected(Successful As Boolean )
If Successful=True Then
Msgbox("ping ok at " & IPofTheOtherDevice & ":" & portOfTheOtherDevice,"ok")
tmr2.Enabled =True
Else
Msgbox("ping error at " & IPofTheOtherDevice & ":" & portOfTheOtherDevice,"ok")
closeStreamsIfOpen
End If
End Sub
Sub closeStreamsIfOpen
' here I put also the aStreams closing process.
If aNewSocket.IsInitialized Then aNewSocket.Close
End Sub
Sub tmr2_tick
Log("tick")
tmr2.Enabled =False
closeStreamsIfOpen
End Sub