Android Question WAIT FOR and TCP

MarcoRome

Expert
Licensed User
Longtime User
Hi all, i have this code:

B4X:
Dim list_server As List
    list_server.Initialize
    list_server.Add("time-a.nist.gov")
    list_server.Add("nist1-macon.macon.ga.us")
    list_server.Add("nisttime.carsoncity.k12.mi.us")
    list_server.Add("nist.netservicesgroup.com")
    list_server.Add("time.nist.gov")
    list_server.Add("utcnist.colorado.edu")
   
   
   
    For i = 0 To list_server.Size -1
        socket1.Initialize("socket1")
        Log("*****---> " & list_server.Get(i))
        socket1.Connect(list_server.Get(i), 13, 20000)
        Wait For (socket1) Socket1_Connected (Successful As Boolean)
        If (Successful) Then
            Log("Connect Successo") '<------- HERE ******
            AStreams.Initialize(socket1.InputStream, socket1.OutputStream, "AStreams")
            Wait For (AStreams) AStreams_NewData (Buffer() As Byte)
            Log("AStreams inizializzata")
            Dim msg As String
            msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
            Log("Time: " & msg)
            'Msgbox("Time received: " & CRLF & msg, "")
            socket1.Close
           
        Else
            Log(LastException.Message)
            socket1.Close
        End If
    Next

in same time work and in another time no.
If i run it always comes to this point '<------- HERE ****** and in some cases does not go on.
What i wrong ?
Thanks
 

MarcoRome

Expert
Licensed User
Longtime User
Hi dear Don. The problem is here:

AStreams.Initialize(socket1.InputStream, socket1.OutputStream, "AStreams")

B4X:
Wait For (socket1) Socket1_Connected (Successful As Boolean)

        If (Successful) Then
            Log("Connect Successo") '<------- HERE ******
            AStreams.Initialize(socket1.InputStream, socket1.OutputStream, "AStreams")

because i see the log "Connect Success" .... but here STOP and this happen in first step ( when i = 0 )... as dont initialize AStreams, the think strain and that in same time work in another time no. More or less work on 10 time 6-7
The disconnect event will work after
AStreams.Initialize(socket1.InputStream, socket1.OutputStream, "AStreams")
as you see in code
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi Erel, thank you for your reply.
I see that after
AStreams.Initialize(socket1.InputStream, socket1.OutputStream, "AStreams")
raise AStreams_Terminated...maybe is problem with internet, or another thing i havent idea
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…