Hi guys, I have designed a simple text chat application but i am expereincing problems with it. I will explain.
When a client connects to the server, the server sends a login request via the printwriter. On the clients screen, this is displayed as 'Login:'. The client must then enter 'Login: ' followed by the desired nick name. Once the client does this, the server will check if there is already a user with that nick name. If not, then the user is added to the vector clients and a new thread is started. Now after the user is successfully logged in, the listen)message(0 method is called to listen for new messages. To send a message, the Client must then type 'Post ' followed by the message. This message is then sent to all users that are currently connected.
The problem I am facing is that when the client tries to send a message, when it is the only client connected, the message is send succesfully but then it cannot send any more messages until it receives a message from the server or another client. It is as if the client must receive a message before it can send. Now when, you have two clients connected, and client A sends a message, client B receives the message and then client A is unable to send any more messages until client b sends a message of its own.
I want the client to be able to send a message without having received one. For example if only one client is connected, I want that client to be able to send messages as many times as it wants even if it is not receiving any messages.
With regards to two connected clients, I want client A to be able to send a message to client B without having to receive a message from client B. I want simultaneous sending and receivng. Is this possible? So far i think the problem is with the BufferedReader and the Printwriter but I can't figure out exactly what it is. I have attached the files to this thread. i would really appreciate it if someone could help me with this before the weekend runs out. Thanks in advance guys
When a client connects to the server, the server sends a login request via the printwriter. On the clients screen, this is displayed as 'Login:'. The client must then enter 'Login: ' followed by the desired nick name. Once the client does this, the server will check if there is already a user with that nick name. If not, then the user is added to the vector clients and a new thread is started. Now after the user is successfully logged in, the listen)message(0 method is called to listen for new messages. To send a message, the Client must then type 'Post ' followed by the message. This message is then sent to all users that are currently connected.