'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 CltSock As Socket
Dim Astreams As AsyncStreams
' If you install the "SocketServer" on local machine - change this ip to "127.0.0.1"
'Dim ip As String : ip = "192.168.0.13"
Dim ip As String : ip = "127.0.0.1"
'Dim port As Int: port = 9092
Dim port As Int: port = 5000
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 btn_client As Button
Dim lbl_status As Label
Dim EditText1 As EditText
Dim txt_out As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("ClientForm")
EditText1.Text = ip
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
lbl_status.Text = msg
End Sub
Sub btn_client_Click
CltSock.Initialize("Client")
CltSock.Connect(ip,port,20000)
End Sub
Sub Client_Connected(ConStatus As Boolean)
If ConStatus = True Then
Msgbox("Connection Successful","")
Astreams.InitializePrefix(CltSock.InputStream, False, CltSock.OutputStream, "AStreams")
Else
Msgbox(LastException.Message, "Error connecting")
End If
End Sub
Sub EditText1_EnterPressed
ip = EditText1.Text
End Sub
Sub txt_out_EnterPressed
If Astreams.IsInitialized = False Then Return
If txt_out.Text.Length > 0 Then
Dim sNewLine As String
sNewLine = txt_out.text & CRLF
Dim buffer() As Byte
buffer = sNewLine.GetBytes("UTF8")
Astreams.Write(buffer)
ToastMessageShow("Sending:" & sNewLine,False)
End If
End Sub