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,550
Last edited:

Shay

Well-Known Member
Licensed User
Longtime User
I updated to Java 8: jdk-8u31
First run looks ok, I will track the service
 

roddy

Member
Licensed User
Longtime User
I tried the sample (B4X push server), this is the log:
What am I missing?

B4X:
2015-03-03 16:16:42.039:INFO::main: Logging initialized @140ms
2015-03-03 16:16:42.101:INFO:oejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-03-03 16:16:42.117:WARN:oejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale zh_TW
2015-03-03 16:16:42.117:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@b1625c{/,file:/D:/B4J/B4X-PushServer/PushServer/Objects/www,AVAILABLE}
2015-03-03 16:16:42.132:INFO:oejs.AbstractNCSARequestLog:main: Opened D:\B4J\B4X-PushServer\PushServer\Objects\logs\b4j-2015_03_03.request.log
2015-03-03 16:16:42.148:INFO:oejs.ServerConnector:main: Started ServerConnector@63ac78{HTTP/1.1}{0.0.0.0:51044}
2015-03-03 16:16:42.148:INFO:oejs.Server:main: Started @265ms
server version: 0.9
server is listening on port: 51044
iospush._connect (java line: 91)
java.io.FileNotFoundException: c:\B4push (摮?鋡急???
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:199)
    at b4j.example.iospush._connect(iospush.java:91)
    at b4j.example.iospush._start(iospush.java:216)
    at b4j.example.main._appstart(main.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.main(main.java:28)
main.main (java line: 28)
java.lang.RuntimeException: java.io.FileNotFoundException: c:\B4push (摮?鋡急???
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.main(main.java:28)
Caused by: java.io.FileNotFoundException: c:\B4push (摮?鋡急???
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:199)
    at b4j.example.iospush._connect(iospush.java:91)
    at b4j.example.iospush._start(iospush.java:216)
    at b4j.example.main._appstart(main.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    ... 2 more
 

Attachments

  • B4J_PushServer_error1.jpg
    B4J_PushServer_error1.jpg
    330.7 KB · Views: 319

Shay

Well-Known Member
Licensed User
Longtime User
looks like this file: (File not found)
FileNotFoundException: c:\B4push
I guess this is the config file?
first make sure file name is in English, second make sure you put it on directory you wrote in the code
 

roddy

Member
Licensed User
Longtime User
looks like this file: (File not found)
FileNotFoundException: c:\B4push
I guess this is the config file?
first make sure file name is in English, second make sure you put it on directory you wrote in the code

Shay, thank you for your reply.

The file name is English. like append picture.

Contents of the file (config.txt) are as follows.

B4X:
#push server configuration

#path to the keystore file. Use unix style slashes:
iPushKeystore=C:/B4push
#same password as the password set in B4i key settings:
iPushKeystorePassword=123456

#change to: gateway.push.apple.com for production
iGateway=gateway.sandbox.push.apple.com
iGateWayPort=2195
AndroidApiKey=AIzaSyDUHKELOT_xxxxxxxxxxxxxxxxxxxxx

PushServerPort=51044
PushServerPassword=123
 

Attachments

  • B4J_PushServer_error2.jpg
    B4J_PushServer_error2.jpg
    116.4 KB · Views: 282

roddy

Member
Licensed User
Longtime User
First test is OK.
When i close the B4X Push Server, and open again.
This log say: Trying to reconnect...
what's happen?

B4X:
2015-03-03 20:56:52.637:INFO::main: Logging initialized @140ms
2015-03-03 20:56:52.699:INFO:oejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-03-03 20:56:52.715:WARN:oejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale zh_TW
2015-03-03 20:56:52.715:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@b1625c{/,file:/D:/B4J/B4X-PushServer/PushServer/Objects/www,AVAILABLE}
2015-03-03 20:56:52.715:INFO:oejs.AbstractNCSARequestLog:main: Opened D:\B4J\B4X-PushServer\PushServer\Objects\logs\b4j-2015_03_03.request.log
2015-03-03 20:56:52.731:INFO:oejs.ServerConnector:main: Started ServerConnector@63ac78{HTTP/1.1}{0.0.0.0:51044}
2015-03-03 20:56:52.731:INFO:oejs.Server:main: Started @250ms
server version: 0.9
server is listening on port: 51044
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:953)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
    at anywheresoftware.b4a.objects.SocketWrapper$1.run(SocketWrapper.java:141)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at sun.security.ssl.InputRecord.read(InputRecord.java:482)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
    ... 9 more
Error connecting socket: (EOFException) java.io.EOFException: SSL peer shut down incorrectly
Trying to reconnect...
 

Shay

Well-Known Member
Licensed User
Longtime User
:) this is exactly the issues I am having
what is the version of your java ?
 

roddy

Member
Licensed User
Longtime User
Run it for several minutes and see whether it reconnects eventually.

I also experienced this issue. In my case it was resolved after I recreated the required keys.

Continue to observe, and try recreate the required keys.
 

roddy

Member
Licensed User
Longtime User
Pushserver run by B4J is OK, But run "Pushserver.jar in cmd windows is No reaction.

My command line:
java -jar pushserver.jar

This command wrong?
 

Attachments

  • B4J_PushServer_error3.jpg
    B4J_PushServer_error3.jpg
    205.1 KB · Views: 296

roddy

Member
Licensed User
Longtime User
I need add field into push.db and Modification program,but Pushserver frequently wrong.
It's very perplex.

B4X:
Program started.
2015-03-13 14:52:48.977:INFO::main: Logging initialized @790ms
2015-03-13 14:52:49.055:INFO:oejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-03-13 14:52:49.070:WARN:oejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale zh_TW
2015-03-13 14:52:49.086:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@a4a92b{/,file:/C:/PushServer/Objects/www,AVAILABLE}
2015-03-13 14:52:49.086:INFO:oejs.AbstractNCSARequestLog:main: Opened C:\PushServer\Objects\logs\b4j-2015_03_13.request.log
2015-03-13 14:52:49.133:INFO:oejs.ServerConnector:main: Started ServerConnector@1b554cc{HTTP/1.1}{0.0.0.0:51044}
2015-03-13 14:52:49.133:INFO:oejs.Server:main: Started @969ms
Emulated network latency: 100ms
server version: 0.9
server is listening on port: 51044
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:980)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1363)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1391)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1375)
    at anywheresoftware.b4a.objects.SocketWrapper$1.run(SocketWrapper.java:141)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at sun.security.ssl.InputRecord.read(InputRecord.java:505)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:961)
    ... 9 more
Error connecting socket: (EOFException) java.io.EOFException: SSL peer shut down incorrectly
Trying to reconnect...
 

Darren69

Member
Licensed User
Longtime User
I downloaded B4J so I could run the server, and out of the box I get an error:-

Error description: Unknown type: byteconverter

do I need to install any extra libraries to make this work?

its a brand new first time install of B4J that I downloaded today.

thanks

Darren
 
Top