Android Tutorial Custom WebSocket Based Push Framework

LucaMs

Expert
Licensed User
Longtime User


Ecco, quindi è necessario usare i WebSocket, così si evita il "polline"

Grazie per l'informazione



So, I need to use WebSockets, to avoid the polling and the.... explosion of the server with just 10K connections.

Thanks for the info.
 

tigrot

Well-Known Member
Licensed User
Longtime User
WebSocket in realtà utilizza un polling invisibile, quindi attento ai volumi e prima di vendere la pelle dell'orso prova!

Websocket is using an invisible polling to realize a Keep-alive function, so be careful with bandwidth and before selling your product.
 

Picena Informatica

Active Member
Licensed User
Longtime User
Websocket open a bidirectional channel (one connection for each client). Standard web polling (from client) open, close and reuse connections.
 

tigrot

Well-Known Member
Licensed User
Longtime User
Yes, but on standard web connections there is no way to send anything to client after it disconnects. That's why is use very seldom Websockets, since i prefer unfrequent polling, to void bombing server!
 

vfafou

Well-Known Member
Licensed User
Longtime User
Hi! I have tested some days all this framework and I can say that it works very well. The only problem I have seen, is that Android takes a long time to send web socket disconnection, but I want to disconnect as immediately as possible!!! Actually, I'm working on a login solution that uses the PushB4A.Id as Username. When the user gives a wrong Username, I have to disconnect and reconnect in order to give connection a new Id, same as the new Username.
I've noticed that when the intent of the Android client is terminated, then disconnection is immediately done!
Thank you in advance.
 
Last edited:

vfafou

Well-Known Member
Licensed User
Longtime User
Send a message to the device that it needs to disconnect instead of disconnecting the websocket immediately.

Hello Erel!
Thank you for your reply. This message will be sent from the server to the device or the device will send a message to tell the server that needs to disconnect?

BTW, I have forgotten to ask you: Is it required to use MySQL instead of SQLite on the server side? The traffic is not so big! I send and receive very small messages. For example: 134,OK,<LONGITUDE>,<LATITUDE>.
I don't know what will be if I connect 300-350 devices.
What do you think?
 

tigrot

Well-Known Member
Licensed User
Longtime User
If you need MySql it's better to write a WEBSERVICE, so you don't have to care about connections(and you DB passwords are not published!) I have written some in PHP and vb.net. If you need them send only have to ask!
 

vfafou

Well-Known Member
Licensed User
Longtime User
Hello tigrot!
Thank you for your reply! I would like to try this web socket push framework and if it is not OK with all these android devices, then I will ask you for help with the web service!
Thank you for your kind suggestion too!
 

coslad

Well-Known Member
Licensed User
Longtime User
hi, i need to use an android devices as server, so it would be nice to write the server with b4a and not with b4j. is it possible?

-----------------

per lucams e tigrot : w l' italia
 

coslad

Well-Known Member
Licensed User
Longtime User
I don't understand why you advise me a HttpServer . I don't know anything about http but i think that it can be easy build a connection with tcp ip socket .
I think that creating an http server includes writing a php page.
Is there any particular reason why I can not create messages that travel through socket tcp ip?

Otherwise have you any good tutorial to study, so i can begin to understand you when you say : "You can use HttpServer to implement an Android server" ?

@ Tigrot

Scusami ma scrivevo dal cellulare , ovviamente "Viva l'Italia"
 

Phunny

New Member
Licensed User
Longtime User
Websocket is cool
nice to made is happen in b4j and b4a
but .. i see not only the data volume but the batterie drain
websocket sends every 2 seconds a keepalive back and forward
i can only imagine the impact of battery drain

i tested with email poll every 30 min all other services stopped
connect locked to hspa only battery was on 20% after 6h
with email like first test and websocket demo which only sends the check back and forward without data passed the cell switched of after 3h because of reaching 1%

both test started with the same battery allways charged to 100%
email was using imap with poll every 30 min without any change of the amount of email.

conclusion: allways-on application on portable devices which mostly stay in background better not use websocket.
at least unless we are able to change the keepalive check params to more relaxed timing.

my 5 cent's
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…