• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Chat server and threads

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
I am developing a chat server.(Initially without any GUI , just on DOS promt)
So i am able to connect as many no. of clients as i want (number not fixed)to server.In server i am starting a new thread for each client connection.And that thread will then take the input from that particular client and give the response back.
But each client i.e. each thread is seperate.So how to pass message coming from one client to all other clients that are connected to my server.
Plus i want that even if any client is not typing any text then also all other messages should be seen on that client.
But if on any client i am using "readLine()" method then the program waits until something is typed on that screen.
So how can i achieve this ?
Please tell me how to send messages across all clients.
[This message has been edited by Anand, Parulkar (edited May 17, 2000).]
[This message has been edited by Anand, Parulkar (edited May 17, 2000).]
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the server you have as many threads as you want and a sort of controller, that has a Vector of all threads (better special interface) that can receive a message. So, when a special server thread wants to send a message to all of the other threads it asks this controller to do it:
controller.broadCast(message);
And broadcast should lock on some object and then send each thread the message.
broadCast() {
...
synchonize (lock_o) {
for (Enumeration e.... }
(ServerThread)e.sendMessage(message)
}
}
...
}
Should look like that.
From the client side you can have two threads, one is for reading and second for getting the data over the network. So, when the client gets some data it puts it on the screen, and when readLine() finishes, you can send your data over the network.
The screen can go crazy, but JDK never had good console io.

------------------
With best of best regards, Pawel S. Veselov ( aka Black Angel )
reply
    Bookmark Topic Watch Topic
  • New Topic