B4J Question HTTP socket client

Roberto Macagno

Member
Licensed User
Longtime User
Hi everyone.

I have to implement the following solution:
A client that should initiate a persistent connection to an HTTP server. It must be able to listen to that connection and when the server sends a request, the client has to pick it up and process and send a reply afterwards to the server (HTTP response format). The line must stay open so the client can receive requests from the server at any time.
I don’t know how the server is built, and I can’t obtaint any information about it (they don’t provide it).

Can anyone help me in how is the best way to develop it?

Thank you in advance.
 

OliverA

Expert
Licensed User
Longtime User
Are there any way to emulate HTTP over TcpSockets (a level below HTTP)
What would that solve? Technically, HTTP is just a layer above TCP sockets. As per @Erel, what API is the server providing?
 
Upvote 0

Roberto Macagno

Member
Licensed User
Longtime User
The server sends me an HTTP request over the persistent connection and I must generate and send an HTTP response (with specific data related with the request).
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The server sends me an HTTP request over the persistent connection
Classical HTTP has no persistent connection. HTTP/2 does have persistent connections and the server can push items to the client, but that involves Service Workers which are implemented in JavaScript (https://developers.google.com/web/fundamentals/push-notifications/). Another approach to persistent connection is the usage of WebSocket technology (https://www.b4x.com/android/forum/threads/39811/#content). So depending on what the server uses to communicate, B4J may not be the optimal platform for your solution. Is this server platform accessible from the outside? If so, what is it? I can't believe that all the info they give is "use a persistent connection and respond to our server's requests." That's pretty crappy.
The server sends me an HTTP request over the persistent connection and I must generate and send an HTTP response (with specific data related with the request).
Reading this again, it almost sounds like you should have a HTTP server that they request information via HTTP (be it GET/POST/etc) and you should be creating a HTTP response.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
You can sign up at www.one.com they support a webhotel with PHP and a mySQL server. You register a membership yearly. You can use a timer to contact the server and perform whatever you need by using GET or POST and have PHP handle the requests. You can use OkHttpUtils2 for this. In case you want to guarantee uptime.
 
Last edited:
Upvote 0
Top