Other B4X Push Server

B4X Push Server is a B4J written back-end server for B4i and B4A apps that use push notifications (Android - GCM, iOS - APN).

Its two main features are:
- Collect device tokens - DeviceToken class.
- Send messages to the devices - Send servlet (which calls iOSPush and AndroidPush modules).

Configuration

There are several settings which you need to configure. The configuration file is located under the Objects folder:

SS-2014-12-24_10.56.25.png


You must set the following properties:
iPushKeyStore / iPushKeystorePassword - Path and password of the push keystore created with B4i (see this tutorial: https://www.b4x.com/android/forum/threads/push-notifications.48562/).

AndroidApiKey - The GCM key from Google developer console (see this tutorial: https://www.b4x.com/android/forum/threads/19226/#content).

PushServerPassword - This value is required when sending messages.

B4A / B4i Apps

The B4A / B4i apps that receive push notifications (client apps) need to register to the push notifications service when they start and send the received token to the B4X push server. You need to configure the push server url in each of the apps.

For the B4A app you need to set the SenderId and to add the required text to the manifest editor.

For the B4i app you need to set the #ProvisionFile attribute to point to the push provision profile.

Server Code

The server code is quite simple and can be customized as needed. It depends on jNetwork library v1.10+ (for the SSLSocket).
The tokens are stored in a SQLite database.

To send a message to all devices (that were updated in the last 3 days) you need to call the Send servlet:
http://<server url>/send?password=<PushServerPassword>&text=Message to send

Apple remote notifications documentation: https://developer.apple.com/library...icationsPG/Chapters/CommunicatingWIthAPS.html
Google GCM documentation: http://developer.android.com/google/gcm/index.html


V0.96 - Fixes an issue with the feedback timer being disabled.
V0.95 - It adds support for iOS feedback service. These lines should be added to existing config files:

#change to: feedback.push.apple.com for production
iFeedback=feedback.sandbox.push.apple.com
iFeedbackPort=2196

The feedback service holds a list of rejected tokens. The server will call it once an hour to find rejected tokens which will then be deleted from the database.

Note that the feedback service isn't working properly in sandbox mode (the problem is in Apple servers).
 

Attachments

  • B4i-PushClient.zip
    3.1 KB · Views: 1,601
  • B4A-PushClient.zip
    7.5 KB · Views: 2,064
  • PushServer.zip
    13.3 KB · Views: 1,664
Last edited:

Shay

Well-Known Member
Licensed User
Longtime User
So what are other options we have
I still cannot make this to work with out issues
always:
SSL peer shut down incorrectly
I noticed that the port is open (telnet to port number is answering) but it cannot connect to apple
and if I send some "wrong" message such as not exist token, socket is terminated and starting again to open the socket (in which I have the SSL peer shut down incorrectly issue)
 

Shay

Well-Known Member
Licensed User
Longtime User
since it can be that someone token has changed, and I sent message to all registered user
so till next time he login and get new token, there is a possibility that I send to non-existing token
and if this user is one of the first users, then it will terminate the socket and all user after this user will not get the message

more stable solution is required here, especially when moving to production, these issues are blocking issues (if I cannot trust this)
 

Darren69

Member
Licensed User
Longtime User
For the life of me I am unable to get this to work with either this tool or the application that Alberto Iglesias wrote - I have deleted all my certificates, provision profiles, App ID's and started again, followed the instructions on the youtube video again to set it all up from scratch and can get my device token ID, but can't seem to send a notification, the Push server just seems to be in a loop of Socket Connected, then terminated, and then trying to reconnect before failing with a load of EOF Exception errors that appear to be the server on apples end refusing a connection. - what would be really helpful would be a step by step instruction guide for getting just a single notification to go, Erel, i know you have video's up on youtube showing it working, but would you be able to post the code that made the magic happen? - Also, is there an interface for the b4Xpush server? or do you just send the messages by sending the sting via a web interface?

thanks in advance, this is the last piece of the puzzle I need to solve before I push out a tool for the folks in my office.

Darren
 

jayel

Active Member
Licensed User
Longtime User
I will post the instructions this evening
I also created service from the b4x server and connected it to internal mysql server instead of the local db in the example
b.t.w I wish to create watchdog so once service has issue it will restart it, but I saw the logs are not created to log file only to "screen output".
it is writing only the http string to the log file (not what I put as log() )

Hallo Shay,

Do you the source code for this, I also need to run against a mysql database
 

Darren69

Member
Licensed User
Longtime User
Hi Again everyone.

I have managed to get the Push server set up on a virtual box sitting on a computer running in my apartment in California. I can send messages to all the devices I have that I use for testing and all is good.

I pushed the current build of my application to the test flight folks and they have installed it, I created a new push.keystore file with the production path set in B4i and set up a new instance of the push server on the machine in California and pointed it to the new push.keystore in the config files. I changed to the non sandbox APN servers, and send a message like before but they never arrive.

if the application is in beta to users using testflight then do I still use the Sandbox servers or the production ones?

Also, do I need to generate new Push.keystore keys for each new version of my software?

thanks in advance

Darren
 

Darren69

Member
Licensed User
Longtime User
Hi,

Yeah I pointed to the production servers in the config files, but messages never get there.

will do some more playing with it.

I do see status = 8 when its supposed to have sent a message which i think means bad token. i am going to delete the token database and start again, maybe that's the problem.
 

fbritop

Active Member
Licensed User
Longtime User
Erel,
What means status=8?
I have changed the configuration files to production (no sandbox) but every time I try to send a message the logs shows as follows:

B4X:
Program started.
2015-05-12 16:59:05.436:INFO::main: Logging initialized @5305ms
2015-05-12 16:59:05.919:INFO:oejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-05-12 16:59:06.043:WARN:oejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale es_CL
2015-05-12 16:59:06.093:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@131463c{/,file:/C:/Users/brito.felipe/Desktop/PushServer/Objects/www,AVAILABLE}
2015-05-12 16:59:06.108:INFO:oejs.AbstractNCSARequestLog:main: Opened C:\Users\brito.felipe\Desktop\PushServer\Objects\logs\b4j-2015_05_12.request.log
2015-05-12 16:59:06.224:INFO:oejs.ServerConnector:main: Started ServerConnector@1138a28{HTTP/1.1}{0.0.0.0:51044}
2015-05-12 16:59:06.227:INFO:oejs.Server:main: Started @6241ms
Emulated network latency: 100ms
server version: 0.95
server is listening on port: 51044
Feedback Socket connected.
feedback terminated
Socket connected.
send message to
status=8
terminated
Trying to reconnect...
Socket connected.

It does work with the sandbox, but then I try with production over a device I have with the production app and it does return the output above.

Any idea what should be wrong?
Thanks
 

Darren69

Member
Licensed User
Longtime User
I am getting the same thing - but I am wondering at what point you stop using the sandbox servers and use the production ones?

I have my app in Testflight at the moment, its not released on the store yet because i wanted to make sure the push notifications were working correctly.

When I build the release app using development keys and the sandbox push server all the notifications I send go to my 2 devices no problems at all.

I used the production keys, built a release app, pushed to the app store for test flight beta testing, loaded on to my devices, deleted the databases for the push server (so it would start clean and have no invalid tokens) changed the configuration file to use the Push.keystore from the distribution apn certificate associated with the release app.

with just a single token from my one device that has the testflight installed release app from the store I get status 8 which is an invalid token

its a real head scratcher can some one that has made this work help me figure this out?
 
Last edited:

Darren69

Member
Licensed User
Longtime User
finally, FINALLY got the production push servers to work with my application that is currently running on testflight - I am not sure if I was doing it wrong the entire time, but what I did this time was create the Push.keystore when I had the aps_production.cer as the certificate file in my application (the application was compiled with the ios_distrubution.cer file.

hopefully this may (or may not) help some one else out.
 

Philip Prins

Active Member
Licensed User
Longtime User
Hello Erel,

I want to use time to live function with GCM so that the message will only be sent for example 30 seconds from sending to GCM.
How can i send this with the message?

Regards,
Philip
 
Top