Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 60
Like Tree2Likes

Thread: How update Jlist in java Chat

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

    Default

    Add more clients to your test and see what happens. What data does each receive?

  2. #22
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    They are all recieving their names and the already existing clients name. but the initial clients are not updated with the new clients

  3. #23
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    Thank you mr tanu.Kansal, i am viewing it right now.
    Quote Originally Posted by tanu.kansal View Post
    hey paaapy u can see my thread
    there ur problem is solved my code is updating user list

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

    Default

    but the initial clients are not updated with the new clients
    What does that suggest about how the server is sending out messages? Who does the server send messages to?

  5. #25
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    yea.. should i be using something like an arraylist there rather than a counter.? thank you

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

    Default

    using something like an arraylist there rather than a counter
    For what purpose? I don't understand what you are referring to.

  7. #27
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    Java Code:
    try {
    			message = (String) input.readObject();
    			clientList[counter]= message;
    			displayArea.append( "\nClient connected : "+message);
    			for (int i=0; i<=counter;i++ )//<------- is this what am getting wrong?
    			{
    				output.writeObject(clientList[i]);
    				output.flush();
    			}

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

    Default

    Please explain why/how the for() loop control could cause the problem?

  9. #29
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    am sorry, i dont know the for loop is the problem, but i am thinking the problem is around there as it is where the server dispatches the message.
    so i tought the for loop is wrong or i should put another control statement in it to redirect the message, i am not even thinking well again. thank you.

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

    Default

    Add printlns to the server that shows what it is sending.
    Look at what it sends and look at what the clients receive.
    What does each client receive and when does it receive it?

  11. #31
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    using
    Java Code:
    System.out.println( String.valueOf() ); or 
    System.out.println( );
    i have being testing and still cant find the end of it, its been very tricky.

    heres what you asked.
    Client writes client_name to outputstream
    server reads inputstream to get client_name
    server stores the name in an array
    and sends it out to everyone
    client in turn reads and displays in JList... please what am i missing?
    thank you..

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

    Default

    Your post #31 states what you WANT the code to do.
    You need to add printlns to the code to show what it is doing.
    I asked: Add printlns to the server that shows what it is sending.
    Where are the print outs that shows what the server sends to the clients?

    Here is what my debug version prints out:
    Running: D:\Java\jdk1.6.0_25\jre\bin\java.exe -Xmx512M -classpath D:\JavaDevelopment;.;..\. JListProblem

    First One started at Thu Aug 25 15:34:05 CDT 2011
    Last One started at Thu Aug 25 15:34:05 CDT 2011
    The Second one started at Thu Aug 25 15:34:05 CDT 2011
    hS B output=null
    hS A output=java.io.ObjectOutputStream@1cde100
    S->Client msg= The Second one, counter=0
    S wO i=0 msg=The Second one
    hS B output=java.io.ObjectOutputStream@1cde100
    hS A output=java.io.ObjectOutputStream@192d342
    S->Client msg= First One, counter=1
    S wO i=0 msg=The Second one
    S wO i=1 msg=First One
    hS B output=java.io.ObjectOutputStream@192d342
    hS A output=java.io.ObjectOutputStream@1c78e57
    S->Client msg= Last One, counter=2
    S wO i=0 msg=The Second one
    S wO i=1 msg=First One
    S wO i=2 msg=Last One
    First One received msg=The Second one
    First One received msg=First One
    Last One received msg=The Second one
    Last One received msg=First One
    Last One received msg=Last One
    The Second one received msg=The Second one

    0 error(s)

  13. #33
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    if this is what you mean, i have never done something like this, i have placed println in specific places to see printouts.

  14. #34
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    how do you do this if i may ask please..

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

    Default

    Java Code:
    how do you do this
    You look at your code to see what variables have useful data to display. The print outs will show the execution flow and anything else you want to know. The order they are printed will tell you lots.
    I changed your code so that it ran in one jvm so all the printouts go to one console.

    Here are some examples:
    Java Code:
    	public void runClient() 	{
                  System.out.println(Client_name + " started at " + new java.util.Date()); //<<<<<<<
    		// connect to server, get streams, process connection
    Java Code:
    		 while ( !message.equals( "." ) ){
    			System.out.println(Client_name + " received msg=" + message); //<<<<<<<<<
    			//genMsg.append("\n"+message );
    Java Code:
    			clientList[counter]= message;
    			displayArea.append( "\nClient  msg= "+message);
    			System.out.println( "S->Client  msg= "+message + ", counter=" + counter);  //<<<<<<<<<<
    Java Code:
    			for (int i=0; i<=counter; i++ ) 			{
                                    System.out.println("S wO i=" + i + " msg=" + clientList[i]);   //<<<<<<<<<<<
    				output.writeObject(clientList[i]);

  16. #36
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    here, for the server
    Java Code:
         C:\Users\PMO\Desktop\Client Server\ClientServer2\Clientserver>java ServerChat
    
        Waiting for connection
    
        Client connected : pappyj77
        int i : 0clientList sent: pappyj77
    
        Waiting for connection
    and client
    Java Code:
          C:\Users\PMO\Desktop\Client Server\ClientServer2\Clientserver>java ClientChat pappyj77
         Attempting connection
    
         Got I/O streams 1
         Client name sent: pappyj77
         message read by client: pappyj77
         value added to JList: by client: [Ljava.lang.String;@53f64158
         pappyj77: = pappyj77
         value[i++]: null
         userList.setListData(value); = [Ljava.lang.String;@53f64158
    is this fine?

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

    Default

    Did you analyze the print outs I posted in post#32?
    They show when and to whom the Server sends messages.

    When the server receives a message, what client(s) does it send the message to?

  18. #38
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    hi am sorry, i really appreciate your help and all, and the problem is probably right infront of me now and i still cant see it.

    i have a terrible headache now and its really late now, i would appreciate if u can point it out if u can but if not, i still appreciate ur effort to show me and thank you very much for u time and effort, i would probably be back if i still cant find it, but u may be away by then.

    thank you...

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

    Default

    What is the answer for this question:
    When the server receives a message, what client(s) does it send the message to?

    Look at the print outs to see the answer or add your own print outs and look at them.

  20. #40
    pappyj77 is offline Member
    Join Date
    Jul 2011
    Location
    kent, UK
    Posts
    47
    Rep Power
    0

    Default

    it writes to the outputstream
    Java Code:
        output.writeObject(clientList[i]);

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 4
    Last Post: 03-31-2011, 11:37 PM
  2. Replies: 2
    Last Post: 03-21-2010, 03:31 PM
  3. Cannot get my JList to update!
    By rangvald in forum AWT / Swing
    Replies: 1
    Last Post: 11-17-2009, 02:57 PM
  4. Help with Java IRC Chat Channel
    By sari in forum New To Java
    Replies: 1
    Last Post: 02-03-2009, 08:21 AM
  5. Java Program chat
    By susan in forum Advanced Java
    Replies: 1
    Last Post: 07-25-2007, 10:05 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
  •