Advertisement

client/server design

Started by December 11, 2003 03:20 PM
0 comments, last by _Twiggie_ 21 years, 2 months ago
I’m in the process of designing a multi-threaded & multi-client server application. It will have a database, and one column in the table will have all the user’s current online status(true/false). Now lets say this will be a chat application, would it be best to have a linked list containing all the connected sockets, so when the server receives the message it just iterates through the linked list and send the data? (then somehow give each socket a unique ID to be able to delete it from the linked list when disconnected). Or iterate through the database, retrieve all the users currently connected, and then send the message? Which would be more efficient/better coding practice? Thanks in advance.
Unless you are expecting really low volumes, you probably don''t want to query the database realtime. Instead load the contents of the database at initialization and then write it back periodically (how often depends on your application).

Instead of a linked list, I chose to store my connections in a hash (STL map) and assign each one a unique id as the key. That way you can quickly load the connections without having to itterate through a list. Another option would be a vector (or array if you can accept a fixed connection limit).

bpopp (bpopp.net)

This topic is closed to new replies.

Advertisement