B4J Question How to read incoming data in a server?

Pablo Torres

Active Member
Licensed User
Longtime User
Hi, I´m trying to build a server that listen on port 17182,
when data comes it has to read the incoming data and answer back

<code>
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region

#AdditionalJar: mysql-connector-java-5.0.8-bin.jar

Sub Process_Globals
Public srv As Server
End Sub

Sub AppStart (Args() As String)
srv.Initialize("")
srv.Port=17182
srv.AddHandler("/AgregarNoticias","InsertNoticia",False)
srv.Start
Log("SFormativas is running (version = 1)")
StartMessageLoop
End Sub
</code>
This is the handle sub in the "InsertNoticia" class module
Sub Handle(req As ServletRequest, resp As ServletResponse)
Try
Log("_jobname: " & req.GetHeader("_jobname"))
Log("Input: " & req.InputStream)
Log(req)

resp.Write("ACA VA LA RESPUESTA")
Catch
Log(LastException)
resp.SendError(500, LastException.Message)
End Try
End Sub

And this is the app code (b4i) that I`m using to send and receive data from the jar in the server

Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
NavControl.ShowPage(Page1)
Dim j As HttpJob
j.Initialize("msg",Me)
j.PostString("http://softuy.ddns.net:17182/AgregarNoticias", "Hola")
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)

End Sub

Private Sub Application_Background

End Sub

Sub JobDone(Job As HttpJob)
If Job.Success=True Then
Log(Job)
Log("Ingreso: " & Job.GetString)
Job.Release
End If
End Sub

The app is working great, it`s very simple, I have no problem reading the data back from the server

What I need to know is how to read, in the server, tha data I did sent by the app, that is the part I dont know how to do
Can anyone help me please?

Many Thanks

PS: Sorry, I didnt find how to set the code part to show it as a code
 

LucaMs

Expert
Licensed User
Longtime User
PS: Sorry, I didnt find how to set the code part to show it as a code
write tags:
[ CODE]
[ /CODE]
(without the spaces I added before, only to show the tags now).

Or use the menu:
upload_2017-6-23_1-51-30.png
 
Upvote 0

Pablo Torres

Active Member
Licensed User
Longtime User
Hi, I´m trying to build a server that listen on port 17182,
when data comes it has to read the incoming data and answer back

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region

#AdditionalJar: mysql-connector-java-5.0.8-bin.jar

Sub Process_Globals
Public srv As Server
End Sub

Sub AppStart (Args() As String)
srv.Initialize("")
srv.Port=17182
srv.AddHandler("/AgregarNoticias","InsertNoticia",False)
srv.Start
Log("SFormativas is running (version = 1)")
StartMessageLoop
End Sub
</code>
This is the handle sub in the "InsertNoticia" class module
Sub Handle(req As ServletRequest, resp As ServletResponse)
Try
Log("_jobname: " & req.GetHeader("_jobname"))
Log("Input: " & req.InputStream)
Log(req)

resp.Write("ACA VA LA RESPUESTA") 
Catch
Log(LastException)
resp.SendError(500, LastException.Message)
End Try
End Sub

And this is the app code (b4i) that I`m using to send and receive data from the jar in the server

B4X:
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
NavControl.ShowPage(Page1)
Dim j As HttpJob
j.Initialize("msg",Me)
j.PostString("http://softuy.ddns.net:17182/AgregarNoticias", "Hola")
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)

End Sub

Private Sub Application_Background

End Sub

Sub JobDone(Job As HttpJob)
If Job.Success=True Then
Log(Job)
Log("Ingreso: " & Job.GetString)
Job.Release
End If
End Sub

The app is working great, it`s very simple, I have no problem reading the data back from the server

What I need to know is how to read, in the server, tha data I did sent by the app, that is the part I dont know how to do
Can anyone help me please?

Many Thanks
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top