I'm building a client / server using Http Server Library
I have two apps, one client :
and a server :
When i click Button1, JobDone return empty string without wait RispostaHttp callsub.
I have two apps, one client :
App Client:
#Region Project Attributes
#ApplicationLabel: Test Client HTTP
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim PaginaHttp As String ="http://192.168.1.161:5555/"
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
Dim j As HttpJob
j.Initialize("", Me)
Dim txt As String = "Test"
j.PostString(PaginaHttp,txt)
j.GetRequest.SetContentType("application/x-www-form-urlencoded")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim tmp As String =j.GetString
Msgbox(tmp,"Risposta")
Log(tmp)
End If
j.Release
End Sub
and a server :
Main Server:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
StartService(ServerHttp)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
CallSub2(ServerHttp,"RispostaHttp","Fatto")
End Sub
Service ServerHttp:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private server As HttpServer
Public port As Int = 5555
Public HttpDevice As String
End Sub
Sub Service_Create
server.Initialize("Server")
server.Start(port)
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo("Http Server Attivo", "", Main)
Service.StartForeground(1, n)
Messages.Initialize
HttpDevice=""
LogColor("Server Http Avviato",Colors.Red)
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)
Try
If Request.Method = "POST" Then 'User pressed on the Send button
Log("Incasso HTTP in corso ")
wait for RispostaHttp (Risposta As String)
Response.SendString(Risposta)
Log("Risposta" & Risposta)
Else
Log("Non è un POST")
End If
Catch
Response.Status = 500
Log("Error serving request: " & LastException)
Response.SendString("Errore server " & LastException )
End Try
End Sub
Sub Service_Destroy
server.Stop
Service.StopForeground(1)
End Sub
When i click Button1, JobDone return empty string without wait RispostaHttp callsub.