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

Shay

Well-Known Member
Licensed User
Longtime User
It is also works fine to me - I am using Amazon EC2 RHEL 7 server
(it is free for 1 year)
 

Shay

Well-Known 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() )
 

Shay

Well-Known Member
Licensed User
Longtime User
I am now having same issue:
"Error connecting socket: (EOFException) java.io.EOFException: SSL peer shut down incorrectly"
it is trying to reconnect in loop and never manage to
 

Shay

Well-Known Member
Licensed User
Longtime User
Additional info:
As I see the port is in listening mode and if I send http to is, it seem to response, but it is writing the errors in loop.

restarting httpd service (apache) did not help
after many try I kill and start it again, it started to work again.
but after I updated the file, it started to show errors again

it is not related to my code
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
It is also works fine to me - I am using Amazon EC2 RHEL 7 server
(it is free for 1 year)

Thanks for this. I too am using Push and need to move it out into the cloud somewhere. This sounds like a perfect place to start.
 

Shay

Well-Known Member
Licensed User
Longtime User
I tried to reboot the server - did not help
I found 1 issue with my code - I don't know if it is related or not:
I found the timeout for retry (which you configured to 30 sec), is written on 2 places, and I changed it to 10 second on 1 place
So I compiled the code again, and now it is ok
 

Shay

Well-Known Member
Licensed User
Longtime User
Erel this is still happening, I cannot understand why
I changed 1 line, compiled it again, and once again it is not working
Can you please investigate this?
 

Shay

Well-Known Member
Licensed User
Longtime User
I stopped it yesterday from re-trying, and just started it again now
and it started ok (without doing anything - same jar from yesterday)
I think something when we kill it, is not clean, and it causes to fail every time till some OS timeout.
I will send logs next time it happen
this issue is not resolved...
 

Shay

Well-Known Member
Licensed User
Longtime User
I meant that I did not complied the code again from yesterday
I am connected via ssh to my server, so there is no network issue
but let's see next time it happen - let me know if you wish me to debug something
(if you explain what exactly you do there)
 

fishwolf

Well-Known Member
Licensed User
Longtime User
if i know well:
I have see that in B4A the push is received from a service (in background)
In B4I is received from a event, but work also if the app not running ?
 

fishwolf

Well-Known Member
Licensed User
Longtime User
I already have a native app that receive push.

i have use the http interface of push server b4j for register the device with the token (gcm_id) generare from native app
I have configure the AndroidApiKey

i have try to send message but receive this error.

Why?

B4X:
feb 19, 2015 9:19:56 PM org.apache.http.impl.client.DefaultHttpClient handleResponse
Avvertenza: Authentication error: Unable to respond to any of these challenges: {}
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
Error sending Android message: Unauthorized
 
Top