• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

help on server/client design

 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic