Sub Process_Globals
Private Socket1 As Socket
Private AStreams As AsyncStreams
End Sub
Sub AppStart (Form1 As Form, Args() As String)
' Initialize socket
Socket1.Initialize("Socket1")
' Connect to TCP server
Log("Connecting to server...")
Socket1.Connect("192.168.1.100", 23, 5000)
End Sub
Sub Socket1_Connected (Successful As Boolean)
If Successful = False Then
Log("Connection failed")
Return
End If
Log("Connected to server")
' Initialize AsyncStreams (NON-prefix mode)
AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")
End Sub
Sub Socket1_Disconnected
Log("Socket disconnected")
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim received As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Log("Received: " & received)
End Sub
Sub AStreams_Error
Log("AsyncStreams error")
End Sub
Sub AStreams_Terminated
Log("AsyncStreams terminated")
End Sub
Sub SendToSever (s as string)
If AStreams.IsInitialized = False Then
Log("Not connected")
Return
End If
AStreams.Write(s.GetBytes("UTF8"))
Log("Sent: " & msg)
End Sub