Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

help on server/client design

Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • 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
Posts: 43016
  • Mark post as helpful
  • send pies
  • 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.
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic