Android Question Chat app without GCM and web server.

Sub7

Active Member
Licensed User
Longtime User
Hello,
i need to implement in my android application a very basic text chat but unfortunately i cannot use the GCM fw, so i was thinking to use my linux server as bridge between the two devices: the devices will connect to the server.
Is not really important that the messages get delivered immediately, neither need of push notification.

I think to use a service for polling my server and retrieve the new messages, i have written a php application that store and retrieve messages, i use json for post an get.
Not sure if is the best way, that script store all the messages on mysql, there will be a large amount of messages exchanged every days, i also don't want to use external services like free chats etc..

I need some directions in how to do this with b4a + server.
Anyone has ever written a chat application without GCM framework using his own server and can post some example please?

Sorry if this is not my first post about this argument.

Thank you.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Without GCM you have nochance for a fast delivery... You app must POLL your server every second to see if there are messages. If so then download. If not, then wait for the next poll.

Without GCM you can NOT send any informations if the app is not polling your server to get new messages.
 
Upvote 0

Sub7

Active Member
Licensed User
Longtime User
Without GCM you have nochance for a fast delivery... You app must POLL your server every second to see if there are messages. If so then download. If not, then wait for the next poll.

Without GCM you can NOT send any informations if the app is not polling your server to get new messages.

Is not really important that the messages get delivered immediately, neither need of push notification.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
So i dont have such example or app written. But the needs can be listed to an list what to do.

Your needs:
- A Webserver where some kind of RDC is possible. Java-RDC, a bridge with php, ASP, and so on. But you need one.
- Your app must register his name" at your server. The server then only allows know users to get/send informations (chatmessages)
- User on Client A writes something in a chatroom. The message is send using httputils2 to the Webserver which gets this informaion and store it in a database, textfile, whatever.
- Client A then POLL the server whether there a unread messages or not. Server send unread messages back to app. Client A shows this messages.
- Client B just want to see the CHAT but dont want to write (maybe later ;-)). Client B do only the registration so the server knows B is online.
Client B then POLL the server every minute/few seconds) to check whether there a unread messages or not. Server send unread messages back to Client B. Client B shows this messages.
Server-Script must learn to know WHO IS ONLINE and which chatmessages is send to Client A, B, c. Server must send messages to Online User if a message is not send before to the users...

your only needs in B4A is to know how to handle and work with httputils2-lib and how to get the answer from the server to be handled.

On Server-side you can write the chatserver in that language what you prefer.
I normally use PHP for such things. I use PHP as RDC for the hole Databaseconnection in my Projects BTW ;-)

But it can be written in ASP, Delphi, C++, whatever... It´s YOUR decision :)
 
Upvote 0

Sub7

Active Member
Licensed User
Longtime User
So i dont have such example or app written. But the needs can be listed to an list what to do.

Your needs:
- A Webserver where some kind of RDC is possible. Java-RDC, a bridge with php, ASP, and so on. But you need one.
- Your app must register his name" at your server. The server then only allows know users to get/send informations (chatmessages)
- User on Client A writes something in a chatroom. The message is send using httputils2 to the Webserver which gets this informaion and store it in a database, textfile, whatever.
- Client A then POLL the server whether there a unread messages or not. Server send unread messages back to app. Client A shows this messages.
- Client B just want to see the CHAT but dont want to write (maybe later ;-)). Client B do only the registration so the server knows B is online.
Client B then POLL the server every minute/few seconds) to check whether there a unread messages or not. Server send unread messages back to Client B. Client B shows this messages.
Server-Script must learn to know WHO IS ONLINE and which chatmessages is send to Client A, B, c. Server must send messages to Online User if a message is not send before to the users...

your only needs in B4A is to know how to handle and work with httputils2-lib and how to get the answer from the server to be handled.

On Server-side you can write the chatserver in that language what you prefer.
I normally use PHP for such things. I use PHP as RDC for the hole Databaseconnection in my Projects BTW ;-)

But it can be written in ASP, Delphi, C++, whatever... It´s YOUR decision :)

Thank you, indeed i've done something like this with PHP.
Now is more clear to me about b4a, thank you for your time!

Still looking for some examples if someone has them! (b4a examples, i can manage the server side stuff)
 
Upvote 0

Sub7

Active Member
Licensed User
Longtime User
Search forum for any examples using "http post", "rdc", "send text to server". If you want i can write a short example how which uses httputils2 sending some infos to a PHP-Script.

I've searched on forum, no much luck!
Thank you very much for your time!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Here you go

PHP-Script used is:

PHP:
<?
if (isset($_REQUEST['action'])){$action=StrToLower(trim($_REQUEST['action']));} else {$action="";}
if (isset($_REQUEST['name'])){$name=trim($_REQUEST['name']);} else {$name="";}
if (isset($_REQUEST['DeviceID'])){$DeviceID=trim($_REQUEST['DeviceID']);} else {$DeviceID="";}
if (isset($_REQUEST['SimSerialNumber'])){$SimSerialNumber=trim($_REQUEST['SimSerialNumber']);} else {$SimSerialNumber="";}
if (isset($_REQUEST['SubscriberID'])){$SubscriberID=trim($_REQUEST['SubscriberID']);} else {$SubscriberID="";}

if ($action == "init"){
    $user = array();
    $user['name'] = utf8_encode($name);
    echo json_encode($user);
}else{
}
?>
 

Attachments

  • sub7.zip
    13.2 KB · Views: 272
Upvote 0

Sub7

Active Member
Licensed User
Longtime User
Here you go

PHP-Script used is:

PHP:
<?
if (isset($_REQUEST['action'])){$action=StrToLower(trim($_REQUEST['action']));} else {$action="";}
if (isset($_REQUEST['name'])){$name=trim($_REQUEST['name']);} else {$name="";}
if (isset($_REQUEST['DeviceID'])){$DeviceID=trim($_REQUEST['DeviceID']);} else {$DeviceID="";}
if (isset($_REQUEST['SimSerialNumber'])){$SimSerialNumber=trim($_REQUEST['SimSerialNumber']);} else {$SimSerialNumber="";}
if (isset($_REQUEST['SubscriberID'])){$SubscriberID=trim($_REQUEST['SubscriberID']);} else {$SubscriberID="";}

if ($action == "init"){
    $user = array();
    $user['name'] = utf8_encode($name);
    echo json_encode($user);
}else{
}
?>

thanks! i will check it when i get home and let you know.
 
Upvote 0
Top