Help on IM Program

Malikman

[H]ard|Gawd
Joined
Sep 1, 2004
Messages
1,045
Hello,
In class we are making a Instant Messenger program. It is not a homework assignment we are working it out in class but we are trying to work around how to fix a problem we have. How we knowing what type of information is passed (whether we are sending the server a username or a message to other people or recieveing a message or a new buddy list to put in the buddy list edit box) is through "protocols" we have set up. ESC 1 Username esc 0 means to the server, "this is a username" etc... we got the buddy list to work. BUT we are having trouble with the server. we want it so when someone sends a message to someone it'll send open a window in the person who we are sending it to if one is not already up. how we are trying this is by having a buddytable were when we get the buddy list we put it in a table with a ptr to a new window and at first i's all null and when someone says we want to talk to this person it'll come in and we pop up the right window. The problem we are having is... how are we going to get this to update when someone exits and how the server determines someone exits and resends the buddy list. Does anybody have any ideas. I know this is probably confusing without code, and the fact that i'm not good at explaining things, but if anyone has any ideas with what i've said or can ask questions that will help me clear thigns up that'd be great.

The server is in C++ on linux and the client program is in C++ on windows using MFC.
 
Okay, I was slightly (perhaps more than slightly) confused while reading parts of that, but if your main concern is how does the server know if a client quits or dies or a cable gets pulled or whatever, a possible solution would be to do pings of clients at set times, and if a client does not respond in timely fashion, they are seen as disconnected.
 
I honestly have no idea what you just said, but I here's what I think from what I think you said.

Why don't you make the client tell the server when it exits by sending a message to the server?

For crashed clients, just add a timeout state to the server. After 10 minutes of inactivity, assume that the client is offline.
 
I'm assuming the server keeps a database of users, their connection statuses, and their buddy lists, and that the server sends a user's buddy list (along with the individual connection statuses) to his or her client at sign in. When a user signs out, it sends the server a message "Hey I'm signing out." The server then updates that user's database entry for connections status.


Now, you can either have the client query the server for the statuses of users on its buddy list. Or you can have the server do a query for all users who have that the user that just signed out and push a status update to all of the the ones that are currently connected.

In the case of user that's not properly signed out (e.g. crashed client, disconnected, etc), do as the others have suggested and ping the connected clients every minute or so. After 10 or so attempts, the server then updates the database to show the user's disconnected.
 
We actually do not have a database of users. The server has a table with a list of users and then sends it to every client when someone logs on, and we have our clients update when we recieve the buddy list.
 
Isn't a table essentially a database? What type of 'table' are you using?
 
i think it's an array of usernames actually that the server ends along with the number of the socket so you know what username corresponds with what socket.

I don't have the code on me at the moment.
 
That makes things easier, in a small-scale environment - though I'd strongly suggest setting up some sort of database to hold this info (mysql is free..)
 
I agree with the MySQL suggestion.

Set up a SQL database and have your IM program query this database for the user information. Have the clients query the database, go through each buddy on the list, retrieve the status (connected, not connected, away or not away), and finally update the buddy list pane.
 
Well, clients should query for that stuff, and the server should query the database. Clients should not have direct access to it.

Your socket library should be able to detect a TCP timeout. No need to ping or anything.
 
Back
Top