Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Norm

Thread: Thread chat client app

  1. #1
    mohsen.noor is offline Member
    Join Date
    Dec 2012
    Posts
    18
    Rep Power
    0

    Default Thread chat client app

    Hello everyone
    I have conceptual question regarding thread in the following code (Head First Java page 518,519)
    Once the first message receive from server thread will be dead
    What will happen in next time when the server sends a message because when we receive at the end of a first message, it becomes null and it come out from while loop

    Thanks


    Thanks
    Java Code:
        class IncomingReader implements Runnable {
            public void run() {
                String message;
                try {
                    while ((message = reader.readLine()) != null) {
                        System.out.println("client read " + message);
                        incoming.append(message + "\n");
                    }
                } catch (IOException ex)
                {
                    ex.printStackTrace();
                }
            }
        }
    Last edited by mohsen.noor; 05-13-2014 at 11:50 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Thread chat client app

    Yes, it looks like it exits the while loop when the message is null.
    mohsen.noor likes this.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    mohsen.noor is offline Member
    Join Date
    Dec 2012
    Posts
    18
    Rep Power
    0

    Default Re: Thread chat client app

    Quote Originally Posted by Norm View Post
    Yes, it looks like it exits the while loop when the message is null.
    How we can sent null message ? to come out the loop

    Thanks
    Last edited by mohsen.noor; 05-13-2014 at 01:10 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Thread chat client app

    What can cause an end of the input stream?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    mohsen.noor is offline Member
    Join Date
    Dec 2012
    Posts
    18
    Rep Power
    0

    Default Re: Thread chat client app

    Closing the connection at the end of the message

  6. #6
    mohsen.noor is offline Member
    Join Date
    Dec 2012
    Posts
    18
    Rep Power
    0

    Default Re: Thread chat client app

    Quote Originally Posted by Norm View Post
    What can cause an end of the input stream?
    Closing the connection at the end of the message

Similar Threads

  1. Chat client with IRC
    By lok pun in forum Networking
    Replies: 3
    Last Post: 09-06-2011, 06:48 AM
  2. Chat Client using Smack API
    By sQu3aKy in forum Networking
    Replies: 0
    Last Post: 05-01-2010, 02:40 AM
  3. Need help with chat client
    By the_flirt in forum Networking
    Replies: 4
    Last Post: 04-23-2010, 03:49 PM
  4. Chat Client
    By Jessi34 in forum New To Java
    Replies: 5
    Last Post: 12-09-2009, 03:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •