alrighty, I have my structure pretty much set up, I have clients connecting to a server, and when they do I initialize a 'ConnectionToClient' for that client.
But what I have now is a waiting queue for the clients as they connect, and then when an admin loggs in, a client and admin are paired up in a 'Chat', and inturn pushed into a Chat stack.
this is all fine and dandy, but what I'm having trouble deciding is, do I need to create a new 'ChatThread' for the Chats, or could I some how synchronize the Chats?
By synchronize I mean, when a client or admin sends a message to the server, the server takes that message, finds the chat with the corresponding socket and then sends that message to the other client in that chat.
this would be ok, but if I have multiple upon multiple clients sending messages at once, I could have messages getting corrupted or mismatched.
On the other hand, if I were to make a new 'ChatThread' for each new chat that comes into play, if I have multiple threads accessing the same static data, I could still run into data problems.
should I just treat each chat as a 'mini-server' and have the chat going on only in that new thread?
In otherwords, have all the sending and recieving only going on in that single chat, so the server doesn't have to find the chat, the message are just getting sent and recieve by functions of that Chat class.
If I could get any better input, or even approvals and dissaprovals of these different approaches, I would really appreciate it.
You down with OOP? Yeah you know me!
Joined: Mar 22, 2005
It's hard to say whether keeping the data within the chat threads or in a global data structure is the better architectural choice. But generally the way around problems with changing shared state (like the global Stack you mention) is to synchronize access to it. That would probably easier to accomplish than to rewrite the code so that it keeps the data in the individual threads.