Java

Moderators: zibadian
Number of threads: 7832
Number of posts: 18231

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
updating and using String in multiple threads Posted by umassEngineer on 2 May 2011 at 11:55 PM
Hello all,

I am attempting to create a basic chat program and I am having some difficulties as I am trying to use threads for it. There is a single Server object that listens for Client connects, and assigns each one to its own thread. The problem is that I'd like all threads to 'receive' any string generated by all clients, for outputting purposes.

Can I have an instance variable in my Server class that each thread can write to as well as outputting that variable if it has been outdated since last check, or is that just nonsense? A little new to threading here...

Thanks in advance,

-UE
Report
Re: updating and using String in multiple threads Posted by djgalore on 11 Jul 2011 at 12:50 AM
Your server needs to keep track of all connected clients. if it receives a message from any client then it needs to notify all other connected clients. You need something like a handler that will control/handle any client request/responses.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.