''Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
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 Socket1 As Socket 'A socket on which to connect
Dim PingTimer As Timer 'A timer to control the process
Dim IPAddress As String 'A string to hold our IP address
Dim IPPort As String : IPPort = "7890" 'I know this is the port on which he is listening
Dim MachineNode As Int : MachineNode = 0
Dim NetworkNode As Int : NetworkNode = 1
Dim lblIPAddress As Label 'just so we can watch what is going on.
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Activity.LoadLayout("IP") 'we want to watch the lblIPAddress text
PingTimer.Initialize("PingTimer", 100) 'I set the interval to .1 second, could be less
End If
PingTimer.Enabled = True 'Ping timer will keep track of the time
End Sub
Sub Socket1_Connected (Successful As Boolean) 'if we get a connection then we are through
PingTimer.Enabled = False
If Successful Then
Msgbox("We found our server" & IPAddress, "Success")
Socket1.Close
Activity.Finish
Else
PingTimer.Enabled = True 'otherwise we re-enable the timer to try the next IP address
End If
End Sub
Sub PingTimer_Tick
PingTimer.Enabled = False
MachineNode = MachineNode + 1
If MachineNode < 255 Then 'here we will increment and test the IP "machine" node
IPAddress = "192.168." & NetworkNode & "." & MachineNode
lblIPAddress.Text = "Trying " & IPAddress
Socket1.Close
Socket1.Initialize("Socket1")
Socket1.Connect(IPAddress, IPPort, 0)
PingTimer.Enabled = True
Else 'if we have tried all 255 machine nodes, increment the "Network" node
NetworkNode = NetworkNode + 1
MachineNode = 0
If NetworkNode >= 255 Then 'alas, there is no socket available
Msgbox("I could not find the server", "ERROR")
Activity.Finish
End If
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub