'Activity module
Sub Process_Globals
Dim ServerSocket1 As ServerSocket
Dim Socket1 As Socket
Dim Timer1 As Timer
Dim InputStream1 As InputStream
Dim OutputStream1 As OutputStream
Dim raf As RandomAccessFile
End Sub
Sub Globals
Dim lblName As Label
Dim lblSize As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Timer1.Initialize("Timer1", 200)
File.MakeDir(File.DirRootExternal, "android") 'probably already exists
End If
'Initialize the server socket if it is not initialized.
'ServerSocket1 will not be initialized when FirstTime=True and after the user
'closed the activity and then opened it again (by pressing on the back key)
If ServerSocket1.IsInitialized = False Then
ServerSocket1.Initialize(2222, "ServerSocket1")
End If
ToastMessageShow("My IP: " & ServerSocket1.GetMyIP, True)
Activity.LoadLayout("1")
End Sub
Sub ServerSocket1_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
Socket1 = NewSocket
Timer1.Enabled = True
InputStream1 = Socket1.InputStream
OutputStream1 = Socket1.OutputStream
ToastMessageShow("Connected", True)
Else
Msgbox(LastException.Message, "Error connecting")
End If
ServerSocket1.Listen 'Continue listening to new incoming connections
End Sub
Sub Activity_Resume
ServerSocket1.Listen
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
Timer1.Enabled = False
Socket1.Close
ServerSocket1.Close 'stop listening
End If
End Sub
Sub Timer1_Tick
Dim BC As ByteConverter
If InputStream1.BytesAvailable > 0 Then
Timer1.Enabled = False
Dim buffer(8192) As Byte
raf.Initialize3(buffer, True)
InputStream1.ReadBytes(buffer, 0, buffer.Length)
ToastMessageShow(bc.StringFromBytes(buffer,"UTF-8"),True)
Timer1.Enabled = True
End If
End Sub