Synchronous Call through Socket

poseidon

Member
Licensed User
Longtime User
I have this code on 'actAskServer' activity
Code: Copy
http://www.b4x.com/forum/basic4android-updates-questions/17744-use-only-socket-send-receive.html#post101709

At first, I made this activity to download the updates, and as you can think
I use it on a button_click event as

StartActivity(actAskServer)

this line bring up an empty layout where the activity downloads the update and when its done, activity auto closes.

thats ok.

--

Now, imagine that I have multiple activities that user interact, and sometimes is the need to ask Server for data.

1-I would like to call the activity from whatever activity but be invisible can this made?

2-Also as I saw when the StartActivity called the only way to 'catch' it, is on the parent Activity_Resume event. for ex. if i do :

Code: Copy
StartActivity(actAskServer)
msgbox("this is a test","test")

this msgbox never will be shown...


to be honest I would like a synchronous call...
for example

Code: Copy
Sub btnMaintain_Click
   actUpdate.Server_IP = serveIP
   actUpdate.Server_Port= 50959
   actUpdate.Connection_Timeout = 20000
   ret = actUpdate.SendCommand("GetProducts") //where SendCommand is a function on actUpdate activity.
   msgbox(ret,"test")
//OR
   msgbox(actAskServer.ReturnValue,"test")
End Sub

any way to do something like this?
 
Last edited:
re

even I do DoEvents VB6 style coding, never enter at Socket1_Connected event, because DoEvents is not multithreading (?)
On the following example stack at Do..Loop

Code: Copy
Sub Process_Globals
   Dim Server_IP As String 
   Dim Server_Port As Int
   Dim Connection_Timeout As Int
   Dim SendCommand As String 
End Sub

Sub Globals
        Dim AStreams As AsyncStreams
        Dim Socket1 As Socket
   
   Dim Success As Boolean 
   Dim CommandWait As Boolean 
   Dim strBuilder As StringBuilder
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Success=False 

    Socket1.Initialize("Socket1")
    Socket1.Connect(Server_IP , Server_Port, Connection_Timeout)
   
   Do  Until Success=True
      DoEvents
      
   Loop 
   
   Return Success
End Sub 

Sub Socket1_Connected (Successful As Boolean)
    If Successful = False Then
      Success=False 
                Return
    Else
      Success=True 
                Return
    End If
End Sub
 
Upvote 0
re

so

1-
the socket OBJonly lives on activity or service

2-
I have the Bactivity and ConnectionActivity

plot :
now Im at Bactivity, is time to connect, I have show ConnectionActivity (?) there is no way to start the activiry without show it?

--

What you think is right to create a service that uses Socket+AsyncStreams OBJs, maybe this is what Im looking for, services can raise events on activities ?


I have no clue about services can you guide me?

thanks.
 
Upvote 0
re

^ :)

overall
when a service started and instantiate a Socket, on Service_Create event this Socket never closes ?
 
Last edited:
Upvote 0
re

how I can see if a service is alive ?

[edit]
ok, I catch it
Code: Copy
Sub Service_Create
    If Query = "" Then
        'no query means that the process was killed.
        'so we load the query from the state file saved by the activity.
 
Last edited:
Upvote 0
Back
Top