I tried that code: http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/
and it works very fine. But that's not really what I looked for.
That code creates a "room", with only one "instance" of websocket. I would like to have as much instances as "one-to-one conversations" like FB.
Someone has any idea how to make privates conversations websocket's chat?
tl;dr: if there are 3 conversations (6 people), I would like to create automatically 3 "rooms".
Thank you so much.
Regards
This could still be handled by one websocket server instance. You'll just have to store for each user1 the corresponding user2. Everytime user1 sends a message it will be forwarded only to user2 and vice versa. To avoid redundant data, you should store the relation between user1 and user2 only once, of course.
Related
I have a scenario for my app which is similar to sending friend request in Facebook.
When user A sends friend request to user B, internally a new friend request document is created. At a later time when user B also wants to send friend request to A, system would find out that a friend request document existed and so they should be friend of each other, no new friend request document would be created.
I'm trying to figure out the case when user A and user B both simultaneously sends friend request to each other which will then create 2 friend request documents and leading to undetermined behaviour...
Thanks for your suggestions.. Really appreciated!
Edit:
A few had suggested to use a request queue to solve this; however,
I'm confused about using queue because i thought it would make my rest api endpoint process requests sequentially. Wouldn't I lose all the benefit of multi-threading by using queue? I can't help but imagine how bad it would be if my service has millions of requests queued and waiting to be executed one by one just due to this issue. Has anyone seen something along similar problems seen in production?
I had similar situation with my client which has concurrent writes in the database, What I have implemented is a Queue service.
Create a request in the queue rather than writing in the database, a separate reader will
read one message from the queue at a time and check if it is valid to write it to
database, write only if there is no previous request.
You can implement your own queue or you can use service like AWS-SQS, rabbitmq, MSMQ etc.
// Specific to your case
In mongodb write operations on a single document are atomic.
mongodb has a feature of unique index.
Hence if you insert the document with an _id(or any other unique index) with person names A and B by creating unique index for both (such as "A_B" by lexicographically sorting the names) before doing insertion. You will inherently be able to insert only one instance of that document.
// General
What essentially we would like to have are transactions but since mongodb doesn't support such, as of now. There are a few tricks to achieve this:
2 phase commits :
https://docs.mongodb.org/v3.0/tutorial/perform-two-phase-commits/
Using an external source to maintain a flag, for example using memcache which supports insertion in transactional manner/Compare and Swap.
Here if you use system calls method in frontend then you should fire one request to frontend from Database when some user like, I send you request then within a sec database send you one system call and your frontend code immediate correct the button text like
"Add a friend" to "incoming request"
or else.
if you are only setting up database then just make a system call which send it to UI when friend request arrives or as you say Document created, the further process will be handled by UI Developer.
Thank you.
if you don't like the answer then I m apologize for that but don't downvote me because I M new in Stack Overflow Community.
We are developing an application in that we are providing VOIP feature using pjsip.We done every thing well upto registration process and adding friends .But We are facing some problems regarding to friends online status.
I explain my problem indetail..For suppose 'user1' is login and has one friend 'user2' then user2 is offline it is correct(b'coz user2 still not login) when user2 login and has one friend user1 then user1 is online it is correct(b'coz user1 already logedin) but user2 is not shown online in user1's friends
can any one solve my problem ,i stuck here for last 3 days. thanks inadvance
Here's a simple exercise using PJSUA app which should help you solve your problem
Start PJSUA app (on default port). Call this pjsua-app1.
Start another instance of PJSUA on another port. Call this pjsua-app2.
To pjsua-app1 add account user1#a.b.c.d:p, to pjsua-app2 add account user2#a.b.c.d:q
To pjsua-app1 add buddy user2 and to pjsua-app2 add buddy user1
On both apps subscribe presence.
You should see them online if they are logged in
I have set up the Openfire xmpp server and it's running good from a client, but i want to use candy with it to create a chatroom (muc), my settings in openfire work and so there is a conference.blabla.nl, that conference server i can connect with Pandion and Tkabber, i log in and ask what rooms are there or if i want to create one myself, that all go well.
When i connect with candy it only connects as i use a proper login name and pass, but i want it to join or create a chatroom on the muc.
When i login with proper username and pass my screen gets grey, but when i type something to the user logged in at candy there will appear that there are messages but only then, i can't read them in candy...
So to go short, i have candy up and running but shows only information when someone sends something.
Anyone knows about it or have some good tips what could work.
I just want a webclient that people can use with a own chosen name like "guest" or something and then log in to the chatroom.
Any help appreciated.
There are three possible options:
On initialization of Candy, specify autojoin with "true" and in the openfire server specify autojoin bookmarks.
On initialization of Candy, specify autojoin with an array of rooms to autojoin
use the roomPanel Plugin to discover existing rooms and be able to join them.
Btw. we have a support mailinglist as well
So basically I need a system like this:
We got users
Users have friends
Now the users if they come on the website they can post an "activity" just like twitter, they type in what they are doing, and all their friends get with a realtime update.
I have looked at lift for a week or three, and I digged into the chat server example, how ever as I said how can I make an comet actor for "activities" that where posted by friends?
I see two general approachs:
Do it the same way like the chat example: Just use one "Chat"server that holds all activities and every user is registred with. If a new activity is posted, every user would be informed and has to check if the activity was posted by one if its friends (via match/PartialFunction probably). If yes it display it, otherwise discard it.
Use one "Chat"server per user and register only the user's friends with this server. Note: I don't know if you need one comet listener per server for each of the user you are following in this case or if a comet listener can listen to several servers. If you need one listener per server, you will have to combine all activities you're listening to before displaying theese.
Approach 1 is closer to the ChatServer example but I would suggest to follow approach 2 since there's less communication in it so it should scale better. Also using different servers should improve scalability since you're able to do partitioning based on that. Of course you will have to some more management than using only one singleton "Chat"server.
I made this question over at the Openfire groups, but it seems to be pretty quiet out there. Maybe someone here at SO works with Xiff/Openfire and has a clue about this:
We are using an external database for users and groups, on Openfire 3.6.4 through Xiff 3.0 beta with our own client.
When a user is added on our database, the roster doesn't get updated. I am logged in as "User1". "User2" is added to the database to the same shared group, so I should see him in my roster. User2 can login and see User1 on his roster, but User1's roster hasn't been updated. Even after log out, User2 still doesn't show up on User1's roster.
Apparently the group is being cached or something. Where should I be looking at for a fix to this problem? Xiff? OpenFire? I found about the property "cache.name.maxLifetime" in the docs, but I'm not sure if this is the property I should be using to get groups to update the members.
In case anybody gets here looking for an answer to this question, you can follow it here:
Groups not updated on Roster from Database using custom DB
There's a partial solution over there at the Ignite Realtime forums.
A better approach would be to use roster protocol (see RFC 3921, section 7) to modify the roster, perhaps by writing a component for OpenFire. This will modify the caches in transit, as well as sending notifications to clients that are currently logged in for the user. As well, you won't have issues with your changes getting overwritten.