Hi guys, someone can tell me why this code don't send "Test line1" and "Test line2" but only "Test line3" and "Test line4"?
I would like to connect, send packet (Test line1 & Test line 2) and disconnect with one touch, but seems that this solutions don't work
Please, help me.
Unfortunately, I'm newbe of B4A
Thanks.
Stefano
B4X:
Sub Process_Globals
Dim Client As Socket
End Sub
Sub Globals
Client.Initialize("Client")
Dim Astreams As AsyncStreams
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub AStreams_Error
ToastMessageShow("Errore", True)
End Sub
Sub Client_Connected (Successful As Boolean)
If Successful = False Then
Msgbox(LastException.Message, "Error connecting")
Return
End If
ToastMessageShow("Connect",False)
Astreams.Initialize(Client.InputStream, Client.OutputStream, "AStreams")
End Sub
Sub SendCommand(text As String)
Dim buffer() As Byte
buffer = text.GetBytes("utf-8")
Astreams.Write(buffer)
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length,"utf-8")
ToastMessageShow(msg, False)
End Sub
Sub Button1_Click
Client.Connect("192.168.0.252",80,2000)
Delay(3000)
SendCommand("Test line1")
SendCommand("Test line2")
End Sub
Sub Button2_Click
SendCommand("Test line3")
SendCommand("Test line4")
End Sub
Sub Delay(nMilliSecond As Long)
Dim nBeginTime As Long
Dim nEndTime As Long
nEndTime = DateTime.Now + nMilliSecond
nBeginTime = DateTime.Now
Do While nBeginTime < nEndTime
nBeginTime = DateTime.Now
Log(nBeginTime)
If nEndTime < nBeginTime Then Return
DoEvents
Loop
End Sub
I would like to connect, send packet (Test line1 & Test line 2) and disconnect with one touch, but seems that this solutions don't work
Please, help me.
Unfortunately, I'm newbe of B4A
Thanks.
Stefano