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,179
  • B4A-PushClient.zip
    7.5 KB · Views: 1,627
  • PushServer.zip
    13.3 KB · Views: 1,197
Last edited:

moster67

Expert
Licensed User
iOSFeedback now works!

2016-01-13 14:08:39.060:INFO::main: Logging initialized @1624ms
2016-01-13 14:08:39.727:INFO:eek:ejs.Server:main: jetty-9.3.z-SNAPSHOT
2016-01-13 14:08:40.239:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@28f67ac7{/,file:///home/mike/www,AVAILABLE}
2016-01-13 14:08:40.321:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened /home/mike/logs/b4j-2016_01_13.request.log
2016-01-13 14:08:40.552:INFO:eek:ejs.ServerConnector:main: Started ServerConnector@129a8472{HTTP/1.1,[http/1.1]}{0.0.0.0:51044}
2016-01-13 14:08:40.577:INFO:eek:ejs.Server:main: Started @3144ms
server version: 0.95
server is listening on port: 51044
01/13/2016 - 14:08:43 - Startup - Connecting to Apple Server to see if there are any tokens to delete)
01/13/2016 - 14:08:43 - Connecting to Apple Server to see if there are any tokens to delete)
Feedback Socket connected.
Socket connected.
Entered sub AStream_Terminated
send message to
number 4
my device is B425711574499AA47C82593CDA62211EA78D681557C3FE0DCE8EDEF2B24DF41A
number 4
my device is E046F1D3296D0F99B4C5125904446AD680CA1BBADF64DCB77D889DCD35ADC2F0
number 4
my device is DCB3A37B426B66D7C9AA25779B02E17BB9C886F645DE09C33A4FCE14B7252238
number 4
my device is 2EEDF5632207168880457DC05EFCBC7D595DBB67E63F631379314BD94182AABF
01/13/2016 - 15:08:43 - Connecting to Apple Server to see if there are any tokens to delete)
Feedback Socket connected.
Feedback data available
Feedback data available
Feedback data available
Entered sub AStream_Terminated
1452690568
Deleting token B425711574499AA47C82593CDA62211EA78D681557C3FE0DCE8EDEF2B24DF41A
1452690568
Deleting token DCB3A37B426B66D7C9AA25779B02E17BB9C886F645DE09C33A4FCE14B7252238
1452690568
Deleting token E046F1D3296D0F99B4C5125904446AD680CA1BBADF64DCB77D889DCD35ADC2F0

Thanks Erel.
 

roddy

Member
Licensed User
I got a error message. (Append picture)
How to fix it ?
 

Attachments

  • PushServer_error1.jpg
    PushServer_error1.jpg
    289.8 KB · Views: 206

Alberto Iglesias

Well-Known Member
Licensed User
Yes, I know, just for try! I use my .keystore generated by B4i, but still appear this message:

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

and this

Error connecting socket: (EOFException) java.io.EOFException: SSL peer shut down incorrectly



And I don´t have any active firewall or antivirus...

My config.txt is like this:

#push server configuration

#path to the keystore file. Use unix style slashes:

iPushKeystore=C:\\Temp\\push.keystore
#same password as the password set in B4i key settings:
iPushKeystorePassword=1234567890

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

AndroidApiKey=AIzaSyxxxxxxxxxxxxxxxxxxxx

PushServerPort=51044
PushServerPassword=123
 
Top