Hello everyone,
I'm developing a basic chat application on
Java using Sockets. In my simple program, a user will be able to communicate with a certain user through a server. Unfortunately, I could not figure out how to communicate between threads as users do not possess the
thread data. Before giving the details, I would first like to present my program logic. For the sake of simplicity, I will not include all the code that is present in my work.
Server Side :
Server.java
This piece of code do communicate between threads (at least it is supposed to do). However, I could not think of a way to retrieve messages from clients.
On the client side, I have this piece of code:
Therefore, my question is, how can I read messages queued in the ClientThread class from ServerListener? Is there anyway to accomplish this? If not, can you propose a different idea which will not interfere with the logic of the program too much? I should also note that this piece of code is based upon someone else's idea. I'm trying to modify it so that it reads objects instead of Strings, and instead of writing to a room of people, sending a message to certain ID.
I think I need to invoke a method inside Server class, but because I'm not instantiating any Server classes inside ClientUI class, this is not possible.