0

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

sandesh
  • 390
  • 6
  • 20

1 Answers1

-1

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.

MHz Code
  • 105
  • 2
  • 9
  • The question is not about storing messages, it is about how to store socket connection or retaining the first connected socket connection of a client. – sandesh Mar 29 '16 at 08:20
  • You can't store a connection.it is possible only when that client is connected.after disconnect , that stored connection has no value. – MHz Code Mar 29 '16 at 08:27
  • there is one solution.you can set specific id for each client , and detect specific client with specific id. – MHz Code Mar 29 '16 at 08:34
  • 1
    If there is a way to store a connection, then I will store that when user connect to server first time with a unique identifier of a user say a name or ID. next time user connect to server then I will update the connection with new connection.Storing message is easy, but pointing that message to the right client is what I want.If there is no way to store connection,I want to know how to resolve this problem. – sandesh Mar 29 '16 at 08:43
  • Client must introduce itself first.for this , you can use Authorization (like all messenger servers).there is no other way.for example , how you can know someone with no Specifications? so the client should give some specifications first. – MHz Code Mar 29 '16 at 09:04
  • You are right. As I said in the above comment the Unique identifier name or ID can help in recognizing the specific client. server get that identifier when it connects to the server first time. I am trying to get it work as @Nick said by stroing them in List Array or I will try to use pickle[ http://stackoverflow.com/questions/4529815/saving-an-object-data-persistence-in-python ]. Thank you for your concern – sandesh Mar 29 '16 at 09:22