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,619
  • B4A-PushClient.zip
    7.5 KB · Views: 2,081
  • PushServer.zip
    13.3 KB · Views: 1,683
Last edited:

marcick

Well-Known Member
Licensed User
Longtime User
For the B4i app you need to set the #ProvisionFile attribute to point to the push provision profile.

I'm investigation where is my problem because everythings works ok in sandbox, but I have continuous "trying to reconnect" (and doesn't work) in production.
Which would be the "push provisioning profile" ?
Is it a normal AppSTore or AdHoc with a non wildcard ID, correct ?
 

marcick

Well-Known Member
Licensed User
Longtime User
Yes, it works perfect in sandbox. Just have this problem changing the config.txt for production.
I'm reading all the threads to understand where I'm wrong.
 

marcick

Well-Known Member
Licensed User
Longtime User
Deleted everything (certificates, provisioning and keystore) and restarted from scratch.
Now it works........
 

kohle

Active Member
Licensed User
Longtime User
Hi,

I have question about the config.txt file of the pushserver.

I made a release jar file. When I put it on an other computer, I need to
1) put the config.txt and push.keystore too ?
2) Is there a need to copy other libs too ?
3) Is it better to put the passwords and keys into the script, for security reason ?

I'm not familiar with java programming.
 

marcick

Well-Known Member
Licensed User
Longtime User
Hi
1) yes
2) no
3) It is supposed the server is your. Once somebody has acces to your server the problem is not to grab that data ....
 

kohle

Active Member
Licensed User
Longtime User
Thanks for the response.

3)

I made an app on android with notification service for a friends company, all works fine,
mysql + php scripts on my webhoster server, notifications via php script and so on.

Than I was asked for building the app for apple.
I did the same like in android, added a type os in the database table and an other
script sending the notification.

Dont work with apple, because apple use a comunication port which my hosting plan dont support.

So I took from the pushserver script only the communication parts to apple, and get
the Ids from my webserver, deleting unused ids and so on. Like I do with android. Everything works fine.

I made a windows Software with the old, but still good, "b4ppc Desktop" to send notifications
via http/request and php script to android and via jar to apple.

So the jar script runs on a local computer at my friends place. That why I dont want to put special passwords/keys in a readable file.
 

marcick

Well-Known Member
Licensed User
Longtime User
ok, you always can take those parameter out of that file and write them encrypted in another file
 

Richard Goh

Active Member
Licensed User
Longtime User
I am testing on the push server and client. But I got below error when trying to send messages to my device.
The error is refer to getIdForName. How can I get/know the device name to use to sent message to my device?

java -cp b4a_gcm.jar anywheresoftware.b4a.c2dm.C2DM send GT-I9082 "Testing message"
java.lang.RuntimeException: java.net.ConnectException: Connection refused: conne
ct
at anywheresoftware.b4a.c2dm.C2DM.getIdForName(C2DM.java:98)
at anywheresoftware.b4a.c2dm.C2DM.sendMessageTo(C2DM.java:48)
at anywheresoftware.b4a.c2dm.C2DM.main(C2DM.java:218)
 

Richard Goh

Active Member
Licensed User
Longtime User
Hi Erel,
Sorry, used a wrong testing program to test. I had managed to setup the server and client. It's working fine now.
Thanks for your efforts and great job.
 

cloner7801

Active Member
Licensed User
Longtime User
When I started the b4x project it logs :

upload_2016-6-7_19-22-29.png


what i should do?
 

Attachments

  • upload_2016-6-7_19-23-21.png
    upload_2016-6-7_19-23-21.png
    34 KB · Views: 430

Erel

B4X founder
Staff member
Licensed User
Longtime User
See the code in the Send module.

This is the most important line:
B4X:
Dim rows As List = DBUtils.ExecuteMemoryTable(Main.db, _
     "SELECT token, type FROM tokens WHERE updated_time > ? ORDER BY updated_time DESC", _
     Array As String (DateTime.Now - DAYS_LIMIT * DateTime.TicksPerDay), 0)
You can modify it as you need and get only a specific token. Or you can just put the token in the request and then create a List with this token.
 

mrjaw

Active Member
Licensed User
Longtime User
One question:
Using B4X Server Push , I dont need to use Google and all API google anymore to send notifications to Android and IOs?
This server can run into a VPS running Linux, not GUI ?

Thks
 

Darren69

Member
Licensed User
Longtime User
Hi Erel,

Is there a way to manually look at the database contents? I know I have some bad iOS tokens in my database, I just compiled the latest version of the Pushserver and it used the feedback service to remove all the bad tokens, but now when I send a push notification where as before i moved to version 0.97 of push server I had 252 messages sent, now 0 are sent and the database file has gone from being 57k to 1k so I have a feeling my database file is now empty - if possible I would like to manually delete the bad keys as I took a note of them.

thanks

Darren
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
now 0 are sent and the database file has gone from being 57k to 1k so I have a feeling my database file is now empty
Note that the database is made of three files, so the size can be misleading.

The database is a regular SQLite database. You can use SQLite Manager plug-in for Firefox or any other tool that can open such databases.
 

karyadi

Member
Licensed User
Longtime User
Hi all,

i try example using ios, b4j apps running ok.
but when i run B4i-PushClient it show error :

Error getting token: <B4IExceptionWrapper: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo={NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}>

what is wrong with that?
when i try use
B4X:
        Dim bc As ByteConverter
        Dim j As HttpJob
        j.Initialize("j", Me)
        j.PostString(ServerUrl & "/devicetoken", "token=" & bc.HexFromBytes(Token) & "&type=1")

it's show blank token.

and i try "http://192.168.88.36:51044/send?password=123&text=tes2" in browser
it's show "Message sent to 1 device(s)."
but nothing show on my iphone.

please help me.
thanks
 
Top