How to store each Client (User) connection in Server in Python? - android

I am working on a project it is like a chatting system over TCP/IP. Android users as Clients connect to server, server code is written in Python. I want to explain what actually my problem is clearly.
Say there are two clients (users) A and B.
When Both are connected to server, the sock.accept returns two soccket connection objects, say "Aconn" and "Bconn".
like below
Aconn , Aaddress = sock.accept();
Bconn , Baddress = sock.accept();
So Now if I want to send a Message from A to B. then Server can forward received message from A to B easily as the object for B is available as "Bconn". we can send the message to B as below.
Bconn.send(datafromA);
Problem comes when B is not connected to server yet(Now Offline). B may connect to server in the future(Online). Now how to resolve this issue ? Is it possible to store that socket connection when users connect to server first time and assigning the same whenever they come online ? Any good solution? Thanks In advance

You should store messages in a file , Database , array , etc.
after B Connected to server , you can send that stored message to B Client.in order to detect specific Client , you should set specific id for each client.

Related

How can I log into my XMPP server silently using Smack?

I am working on a chatIM client for Android devices and I am having the following problem:
12:34 A goes disconnects from XMPP server
12:36 B send A a message --> A receives GCM message and connects to server to download message --> B sees A's last active time as 12:36
B should see A's last active time as 12:34, not 12:36. Even though A had to connect to the server to download the new message, the user did not actively open the app.
I believe the problem is that when you login (public synchronized void login(CharSequence username, String password, String resource)), there is no way of setting the presence to silent.
Does anyone know of a way to login to your server silently using the Smack library?

Push notification for android app by GCM

I am working on android app for events reminder , this app only display event as list and details about it .. some event's date is change .
I need to push notification to remind a user about event date
I'am Confused when read about Google Cloud Messaging ( GCM )
Is it necessary to request from the user to enter name or email through the application ? I don't need that !
where can I write a new notification "message" to send it ?
Thank you ,
The requirement is simple.
You need to generate gcm token from each of your client.
Client A installs your application and upon launch/login(wherever it fits in your business logic) you will try to generate this gcm token(let us say 10000 is the generated token) . And you need to send this token to your server to store for using it in future communication. when you want to communicate with this client A, you need to tell gcm server,
Hey Gcm server, send mobile with gcm token 10000 the following message "Event time updated"
So if client b installs, it will generate its gcm token and send it to server in same way.
In case you have user login or some way where each user can be identified uniquely, it is recommended to store it along with user details. (along with name, unique id, etc... )
If you do not have login, you can still send token to server and store but what you loose out is the cases where You want to send update to Client A but not B.
Coming to code point of it.
Client code:
For generating gcm token:
https://github.com/googlesamples/google-services/tree/master/android/gcm
after you generate you need to send this token to server
Server code:
server receives the token and stores.
When you want to send a particular message in later point of time, you can send json data or plain message to client.
For example, Following is the python example.
import gcm
response = gcm.json_request(registration_ids=reg_ids, data=in_data, delay_while_idle=False)
Hope this helps.

How to send Google Talk (XMPP) messages with only gmail Adress?

i searched this but i couldn't find any solution ...
I want to develop an application in android , in this application you have a friend list. i want to you can send messages with XMPP to your friends, and get messages with XMPP through Google Talk Server . For be able to do this, i created a instance application about sending Google Talk (Xmpp) messages between two Android devices with this link and this link. i used asmack.jar for this and now i can send messages between 2 device. But Problem is this ;
i have two gmail addresses , for example foo#gmail.com and bar#gmail.com .
for chat between 2 devices and send message from first one to second recipient , i have to write "bar#gmail.com/Smack014GAB5B....." as recipent address . if i only write "bar#gmail.com" as recipient , i can't send it ...
Question is , how can i send message to recipient without "Smack014GAB5B..." extension after "/" ?
Any help would be great ...

How to send an image both side using WIFI Direct?

I am working on an app where ,i am able to send an image only one way,from client to groupowner.How can i send it in both ways?
I had done bi-directional data transfer in my project. In Wifi Direct group owner Ip is decided by OS itself which is known to both devices i.e Server as well as client. Client know the IP of server on which it has to send data, But server don't know the client IP.
For that you have to send client IP address to server and store that address in sharedPrefrences. So you should initiate transfer silently when connection made so that server store the client IP, for next transfer.
Socket client = serverSocket.accept();
String WiFiClientIp = client.getInetAddress().getHostAddress();
you can made a check while transfer i.e if IP don't match server Ip then send data to client IP.
For testing purpose when you send file from client to server, in AsyncTask doinbackground method you can get the IP address of client which is also decide by OS itself. Put that IP statically then you will be able to send file on client also.
I will share my code on github soon. I hope this info will help you.
Working Bi-Directional Data Transfer APK File-> https://play.google.com/store/apps/details?id=anuj.wifidirect&hl=en

How to check username and password in a PostgreSQL server from Android?

I am using the Android 2.2 API. I want to know how to connect to a PostgreSQL database server.
I am new to this and so have no ideas, so please help me with some sample code.
You usually don't connect directly to a database.
To achieve the results you want, you can do a RESTful request.
This means, send either a JSON string or xml file to a server(which you can program in php, ruby and what not)
I'm not going to give you sample code cause there are literally tons of code on a simple google search "android restful login"
Example tutorial
The process is usually:
Enter login credentials on android device -> send post request to server -> validate credentials to the database(postgres in this case) -> send verification back -> android device act upon verification(usually by loading a new activity as a result if logged in successfully)

Categories

Resources