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

kreativa

Member
Licensed User
Longtime User
ok i've fixed the problem
was really a problem with the keys!!
now push server it is able to send push message but on log it says: Token added: 956033EF47D04A4xxxxxxxxx
send message to
status=8
why it returns status=8 (invalid token)! the toke seems ok
 

kreativa

Member
Licensed User
Longtime User
Hi!
The last (i hope) problem.
When i call pushserver it replies "Message sent to 1 device(s)."
but on the log console it replies
send message to
status=8
terminated
trying to reconnect
Socket connected

Nobody can help me??
 

kreativa

Member
Licensed User
Longtime User
I deleted several times the db recreating new token but the response was the same.
I'm trying to send push message to my app that is in developer mode.
 

kreativa

Member
Licensed User
Longtime User
ok solved.
Were the provisioning profile!!

everything works
thanks Erel you are great!!
 

tufanv

Expert
Licensed User
Longtime User
I checked the "running your server on vps" tutorial by Erel,

For this pushserver example. do i need to run pushserver.jar on my vps with given instructions at that post ?
 

tufanv

Expert
Licensed User
Longtime User
Yes. It is not different than any other B4J server app.

I asked my server admin to do this and he asks about this to continue with the operation :
"Also, provide us with more information on your Java application requirements, e.g. do you want us install JBoss, Tomcat or GlassFish on your server etc."

What should i reply :)

edit: I replied them do what the topic says and they did. works perfect ty
 
Last edited:

moster67

Expert
Licensed User
Longtime User
For quite some time, I have been running the PushServer sucessfully on my VPS running CentOS 7. It is located in /home/mike/pushserver/.
However, now I have permission errors (that is what I think). I can start the pushserver (logging in as root and/or my username) and the database itself, push.db, is created however the table "token" is not created.

Anyone knows what to check in my vps-configurations to resolve this issue?

Thanks.
 

moster67

Expert
Licensed User
Longtime User
The tables will only be created if the file doesn't exist. If you want to create a new database then you need to delete the push.db file (as well as the other two push.db files if they exist).
Yes, I know that. I have tested by deleting first the DB and the relevant files so I was sure that a new DB would be created.

The first time I run the pushserver, it does indeed create the DB but it fails to create the table "tokens". The pushserver is also running and seems to work fine. I can successfully pass on messages to send although I get the html-page saying that 0 message was sent. This log message confirms that the server is up and runnning:

B4X:
8X.2XX.52.X00 -  -  [10/Dec/2015:08:29:13 +0000] "GET /send?password=123&text=test HTTP/1.1" 200 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36"
8X.2XX.52.X00 -  -  [10/Dec/2015:08:29:16 +0000] "GET /favicon.ico HTTP/1.1" 404 289 "http://www.mysite.com:51044/send?password=xxx&text=test" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36"

This is the log when the database is created (and looks good):
B4X:
Creating new database.
CreateTable: CREATE TABLE IF NOT EXISTS [tokens] ([token] TEXT PRIMARY KEY, [type] INTEGER, [updated_time] INTEGER)
2015-12-10 09:24:08.722:INFO::main: Logging initialized @19660ms
2015-12-10 09:24:11.700:INFO:oejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-12-10 09:24:12.464:WARN:oejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale en_US
2015-12-10 09:24:15.388:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@2d6a9952{/,file:/home/mike/pushserver/www,AVAILABLE}
2015-12-10 09:24:15.490:INFO:oejs.AbstractNCSARequestLog:main: Opened /home/mike/pushserver/logs/b4j-2015_12_10.request.log
2015-12-10 09:24:16.222:INFO:oejs.ServerConnector:main: Started ServerConnector@445b84c0{HTTP/1.1}{0.0.0.0:51044}
2015-12-10 09:24:16.224:INFO:oejs.Server:main: Started @27969ms
server version: 0.95
server is listening on port: 51044
Feedback Socket connected.
Socket connected.
feedback terminated

But as you can see from the attached image there is no table in the push.db after it was created....

So I am wondering if I need somehow to assign permissions to SQLite to get it working? It used to work but all of sudden it does not.
This is surely not a problem with B4XPushServer but some kind of permission problem on my VPS.

PS: I have tested by logging as root or with my user (using sudo) but no luck. I also had a look at the logs in the /var/log directory but could not find anything which may be related.

Any ideas or help will be most appreciated.
Thanks
 

Attachments

  • db.png
    db.png
    60 KB · Views: 243
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
My guess is that the table was created successfully. You are only copying the db file so you are missing some of the data (that is in the other two files).

Don't use this db browser.

List the tables with:
B4X:
For Each row() As String In DBUtils.ExecuteMemoryTable(db, "SELECT name FROM sqlite_master WHERE type='table'", Null, 0)
     Log($"Table: ${row(0)}"$)
Next
 
Top