Android Question AsyncStream.Write max number of bytes to transmit

Eduardo Funabashi

Member
Licensed User
Longtime User
Hello.
I´m using Astreams.Write() to comunicate to my PC server.
I have problem sending more than 400 bytes.
If I send less than 380 bytes, I get Astream_NewData() event. And all works fine.
When I send more than 400 bytes I do not get Astream_NewData() event. That´s my big problem.
Is there a limitation on this Astreams.Write() method ?
Does anybody knows how to solve this issue ?

Regards
 

Eduardo Funabashi

Member
Licensed User
Longtime User
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
 
Last edited:
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi Eduardo.
This is a community, so ask questions to everyone
1. Pls the next time, when you write code, use this:

upload_2017-9-29_17-44-50.png


2. What's Rotinas ? Do you tried as said Erel with:
AStreams.InitializePrefix(Socket1.InputStream, False, Socket1.OutputStream, "AStreams")
??
 
Upvote 0

Eduardo Funabashi

Member
Licensed User
Longtime User
Hello Erel.

Attached is a piece of code from PC Server Side.
Code for tablet is the same as posted above.

Regards
 

Attachments

  • B4ACODE.txt
    8.4 KB · Views: 211
Upvote 0

Eduardo Funabashi

Member
Licensed User
Longtime User
Eduardo, Erel intendeva che dovresti sistemare il post #4 inserendo il codice come ti ho suggerito io nel post #5 punto 1

I tried this code. But server side does not receive any data

Rotinas.AStreams.InitializePrefix(Rotinas.Socket1.InputStream, False, Rotinas.Socket1.OutputStream,"Astreams")
 
Upvote 0
Top