Android Tutorial Custom WebSocket Based Push Framework

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
I would like to ask you if it is possible to make a class at the server application (B4J), running in its own thread and do the following work:
Fetch from the database some records and send to the clients (tablets) some information.
Having a timer (or is it any other and better way???), looking for changes to these records and resend to the clients the new information.

Thank you in advance!
 

Jerez

Active Member
Licensed User
Longtime User
I've a little problem. I've implemented this awesome piece of code and it work at home. But when I run this solution in another "internet provider" (my office) does not work!!

Can the internet provider or router lock push messages? I've solved the problem adding a router B to the router A (my internet provider).
At this time I can't sell my app with this problem. Any tip or solution?

I'm using the port 51042 "ws://myipaddress:51042/push/myservice" could be the problem?

Use port 80 cloud be possible?
 
Last edited:

Jerez

Active Member
Licensed User
Longtime User
You can use any port you like.

Is the server firewall configured to allow incoming connections on the relevant port?

Hi Erel:

The B4J App is running in a Raspberry Pi board. The board is connected with RJ45 to a router from the internet provider. And the Android phone need to be connected outside home with the public ip of the Raspberry pi.

The Android phone has the raspberry pi public ip and port.

What can I do if the router (provider) block all ports and just have open the standard ports such as 80, 21, 443, etc?

Think in a client that don't know what is a "firewall" and don't have access to the router settings. What can I do in this case?

You say:You can use any port you like.

I've tried the port 80 but Error:

B4X:
srvr.Initialize("srvr")
    srvr.Port = 80  '51042
  
    PushShared.Init
    srvr.AddWebSocket("/push/myservice", "PushB4A")  
    srvr.DebugNetworkLatency = 200
    srvr.Start

java.net.BindException: Address already in use: bind
 
Last edited:

Jerez

Active Member
Licensed User
Longtime User
Please start a new thread for this in the B4J forum.

Sorry Erel. but you make this thread based in an example framework with B4J server and B4A client code. My question is not about code! just setup! The solution could help to others in same problem. so?
 

cbal03

Member
Licensed User
Longtime User
Exactly. For it to be helpful to other developers who deploy B4J servers it should be posted as a new thread in B4J forum.
was a new thread started for this question?
Were you able to solve this problem? I couldn't find thread for this problem.
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hi to all
I made a simple solution (client / server) test. I found that when the device is inactive for some time, it lose the connection and bring no more messages.
There is a way, as other applications (email, WhatsApp) to force sending messages?

thank you
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hello (ciao) Tigrot
there is the risk of creating too much traffic to the server (if you have many apps) and consume too much battery of the device?

Possible that there is another way to keep alive the connection and allow you to send push messages to the app when there is an event?

thank you

p.s. piacere di conosceti...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is a way, as other applications (email, WhatsApp) to force sending messages?
Yes. Use GCM or FCM (firebase push notifications service).

there is the risk of creating too much traffic to the server (if you have many apps) and consume too much battery of the device?
It will not generate too much traffic. Hard to say about the battery. However if you are looking for a simple push framework then you should use Firebase Notifications.
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Yes. Use GCM or FCM (firebase push notifications service).
It will not generate too much traffic. Hard to say about the battery. However if you are looking for a simple push framework then you should use Firebase Notifications.

ok, I'll try this solution, even if it costs me a job rewriting code.

I take this opportunity to ask you if this system also works to launch the procedures for exchanging data automatically between the app and the server?
Thank you
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Your app will start when a push messages is received. You can do whatever you like at that point.

Erel
thanks you for the answer, but I do not understand why an external message can reactivate the connection and not the example timer?
Possible that there is no other way to start the messages with the service timer?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…