wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes help on server/client design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "help on server/client design" Watch "help on server/client design" New topic
Author

help on server/client design

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
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.

Thanks Again,

Justin Fox


You down with OOP? Yeah you know me!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41057
    
  43
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.


Ping & DNS - my free Android networking tools app
 
Consider Paul's rocket mass heater.
 
subject: help on server/client design
 
Similar Threads
client-server based Query
How to break blocked write operation???
Building Requirements for Games
Taming the network problem
Help with Chat Program, update user list