Dim AStreams As AsyncStreams
Dim TCPSocket As Socket
Dim TCPAddress As String
Dim TCPPort As Int
Dim TCPDelay As Int
Private Button1 As Button
Private TextField1 As TextField
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
MainForm.RootPane.LoadLayout("async") 'Load the layout file.
MainForm.Show
'initialize connection with port
Initialize
End Sub
Public Sub Initialize
TCPAddress ="192.168.0.30"
TCPPort = 2000
TCPDelay =5000
TCPSocket.Initialize("TCPSocket")
TCPSocket.Connect(TCPAddress , TCPPort, TCPDelay)
End Sub
Public Sub TCPSocket_Connected (Successful As Boolean)
If Successful = False Then
Log("Connection Failed")
'
End If
AStreams.Initialize (TCPSocket.InputStream,TCPSocket.OutputStream, "AStreams")
Log("Connected")
communicate
End Sub
Sub AStreams_Error
Log(LastException.Message)
Log("Error of rec")
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Log("new dataa test")
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Log(msg)
Log(msg)
End Sub
Public Sub communicate
Dim s As String
s="test"
If AStreams.IsInitialized = False Then
Log("AStreams not Initialized")
Return
Else
Log("Async initalized")
End If
Dim buffer() As Byte
buffer = s.GetBytes("UTF8")
AStreams.Write(buffer)
Log("Sending: " & s)
End Sub
Public Sub Close
AStreams.Close
TCPSocket.Close
End Sub