Hello Erel & Marco
I do connection using code below.
On PC server side data is received complete and server sends data acknowledge back to B4A, that does not generate data received event.
If I send less than 370 bytes all works fine.
Please help with some code.
Regards
Dim AStreams As AsyncStreams
'
' connect to server
'
Sub Conecta_Com_Servidor
Try
Rotinas.Socket1.Initialize("Socket1")
Rotinas.Socket1.Connect(Rotinas.ServerIp ,Rotinas.port, 5000) ' 5segs
Catch
Log("error: " & LastException)
End Try
End Sub
'
' Event when connected
'
Sub Socket1_Connected (Successful As Boolean)
'Dim clr As Int
Try
If Successful = False Then
'Msgbox(LastException.Message, "Erro de conexão")
Msgbox("Connection error", "Error")
' close conn
Log("closing - Socket1_Connected_Error")
Rotinas.AStreams.Close
Rotinas.Socket1.Close
Activity.finish
Else
'ToastMessageShow("Server Conected!", True)
Rotinas.AStreams.Initialize(Rotinas.Socket1.InputStream,Rotinas.Socket1.OutputStream,"Astreams")
Dim buffer() As Byte
buffer = Rotinas.MENSAGEM_TCP.GetBytes("UTF8")
Dim TAM As Int
TAM = buffer.Length
' buffer data has STX & some data & ETX
' problem occurs here when buffer has more than 370 bytes and then I do not get AStreams_NewData event neither AStreams_Error
Rotinas.AStreams.Write(buffer)
End If
Catch
Msgbox("Servidor connection error", "Error")
' close
Log("closing - Socket1_Connected_Error")
Rotinas.AStreams.Close
Rotinas.Socket1.Close
Log(LastException)
End Try
End Sub
'
' Event data received
'
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
'ToastMessageShow( msg, True)
' data received
Log("closing - chegaram dados")
Rotinas.AStreams.Close
Rotinas.Socket1.Close
'
Trata_Mensagem_Recebida( msg ) ' get data received
End Sub
'
' error
'
Sub AStreams_Error
' fecha
Log("closing - AStreams_Error")
Msgbox("Erro de comunicação","Erro WiFi")
Rotinas.AStreams.Close
Rotinas.Socket1.Close
'ToastMessageShow( LastException.Message, True)
End Sub
'
' analize data received
'
Sub Trata_Mensagem_Recebida( msg As String)
' use data received
End Sub