Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Chat application problem

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Chat application problem

    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.
    Attached Files Attached Files
    Last edited by helloworld922; December 10th, 2009 at 11:00 PM. Reason: Please don't post multiple posts/topics asking the same question.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Chat application problem

    Hello there,

    Looking at your Client.java code. It would appear that when you reach your while loop at the bottom you call userInput.readLine(). Now this will stop the execution of the rest of the thread and wait for user input, this means that as long as the client doesn't actually press return or write anything its screen will never be updated with the incoming data from the msg_reader.

    This also works the same way for the msg_reader where you call readLine on that which then puts that into a waiting state waiting for a full line to be written to that stream before you output it and allow the user to input data.

    You might be better off doing this using Swing or AWT and printing the chat stuff in a proper window, you can then have a thread running on the client which just waits for input from the server and prints it to the window while you then have listener which waits for a return key press from the user before it sends data to the server.

    If I have some spare time I might knock something like this up for you to have a look at.

    // Json

Similar Threads

  1. Replies: 0
    Last Post: December 3rd, 2009, 03:43 PM
  2. Application Continued (problem)
    By Riston in forum AWT / Java Swing
    Replies: 6
    Last Post: November 26th, 2009, 02:33 PM
  3. Replies: 1
    Last Post: October 20th, 2009, 06:31 AM
  4. application Task problem - updating JTree
    By idandush in forum AWT / Java Swing
    Replies: 2
    Last Post: June 18th, 2009, 03:15 AM
  5. SSL Chat implementation
    By Koren3 in forum Java Networking
    Replies: 6
    Last Post: April 24th, 2009, 08:20 AM