Android Question AsyncStreams is too slow !!

poya10

Member
Hi, I want to send variables at high speed but AsyncStreams is very slow (300 milliseconds), the transmission time between each data is 10 to 50 milliseconds, so AsyncStreams can not be responsive, it is suitable for normally receiving and sending , But in part of my aplication needs to (just send) high speed data. So what can i do?
 

KMatle

Expert
Licensed User
Longtime User
But in part of my aplication needs to (just send) high speed data

Beneath Erel's comments:

How much data? Megabytes? Gigabytes? Or just "some bytes". Is it WiFi or 4G? Via Router at home? How fast is your device? How good is the connection? 10 MBit which is max. 1 MByte per second minus WiFi encryption and many other things. If the router is busy (many devices/traffic) there's more "loss"/"latency".

It's like: "I have a Porsche but I can only drive at 60 mph" :cool:

You can try UDP also if it's just some bytes.
 
Upvote 0

poya10

Member
Beneath Erel's comments:

How much data? Megabytes? Gigabytes? Or just "some bytes". Is it WiFi or 4G? Via Router at home? How fast is your device? How good is the connection? 10 MBit which is max. 1 MByte per second minus WiFi encryption and many other things. If the router is busy (many devices/traffic) there's more "loss"/"latency".

It's like: "I have a Porsche but I can only drive at 60 mph" :cool:

You can try UDP also if it's just some bytes.
I just want to send a variable in the range 0 to 255 as follows: A100, A20, A126 or any other value, but they are sent at high speed and the time interval should be less than 50 milliseconds , I tested it with the program (Serial WIFI Terminal), it had no problem and it sent quickly, but with my program, it has a delay of 300 milliseconds.

To find a better solution I put my code:

Starter:
Sub Process_Globals
    Private nid As Int = 1
    
    Dim WiFi_Socket As Socket
    Dim TcpStreams As AsyncStreams
    'Dim ast As AsyncStreamsText
    Dim ServerSocket1 As ServerSocket

    Dim ServerIp As String = "192.168.1.50" 'IP Access point 
    Dim Port As Int = 808'    port
    
    Dim noti As Notification
    
    Dim data As String
    Dim connection As Boolean=False
    
    Dim userdisconnect As Boolean=False
    
    Private lock As PhoneWakeState
    
    Dim stg As AriaSharedPreferences
End Sub

Sub Service_Create
    lock.PartialLock
    
    WiFi_Socket.Initialize("WiFi_Socket")
    
    stg.Initialize("s5")
    
    ServerIp=stg.GetString("IpAddress","192.168.1.50")
    Port=stg.GetString("Port","808")
    
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER

End Sub

Sub WiFi_Socket_Connected (connected As Boolean)
    
    If connected = True Then
        Dim vibr As PhoneVibrate
        vibr.Vibrate(200)
        connection=True
        TcpStreams.Initialize(WiFi_Socket.InputStream,WiFi_Socket.OutputStream,"tcpStreams")
        Main.connectionState=1
        CallSub(Main,"SetState")
        StartService(Me)
        
    Else if userdisconnect=False Then 
        Dim vibr As PhoneVibrate
        vibr.Vibrate(500)
        connection=False
        
        Main.connectionState=2
        CallSub(Main,"SetState")
        
    Else If userdisconnect=True Then
        connection=False
        
        Main.connectionState=3
        CallSub(Main,"SetState")
        userdisconnect=False
'        Main.Button1.TextColor = Colors.RED
    End If
        
End Sub

Testpage:
Sub Activity_Create(FirstTime As Boolean)
 
    Activity.LoadLayout("test")

    pulse.Initialize("pulses",100)

End Sub

Sub pulses_tick

    If pul=True Then
        pul=False
        B4XSeekBar2.Value=0
        Starter.TcpStreams.Write(("A0").GetBytes("UTF8"))
    Else if pul=False Then
        pul=True
        B4XSeekBar2.Value=100
        Starter.TcpStreams.Write(("A100").GetBytes("UTF8"))
    End If
  
End Sub
 
Upvote 0

poya10

Member
1. It is not AsyncStreams that is too slow. It is the underlying connection. AsyncStreams simply delegates the data to the underlying stream.
2. Make sure to test it in release mode.
I work with ESP 8266 module, this program is for sending and receiving information from it, the goal is to convert the sensor data of the phone to a number between 0 and 255 in a part of my program and then send it with a low delay, At first I thought there was a problem with the WiFi module or a delay in its arduino program, but this was not the case and by sending the data through another application, I realized that AsyncStreams was sending with a delay.
I also did the following:
1) I also compiled the program in release mode. The problem still exists.
2) I connected to the module both through the router and through the access point of the module itself, it still has a problem (I emphasize that it works properly with the Serial WIFI Terminal program in all cases).
 
Upvote 0
Top