Results 21 to 40 of 60
Thread: How update Jlist in java Chat
- 08-25-2011, 04:56 PM #21
- 08-25-2011, 05:06 PM #22
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
They are all recieving their names and the already existing clients name. but the initial clients are not updated with the new clients
- 08-25-2011, 05:08 PM #23
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
- 08-25-2011, 05:12 PM #24
What does that suggest about how the server is sending out messages? Who does the server send messages to?but the initial clients are not updated with the new clients
- 08-25-2011, 05:25 PM #25
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
yea.. should i be using something like an arraylist there rather than a counter.? thank you
- 08-25-2011, 05:28 PM #26
For what purpose? I don't understand what you are referring to.using something like an arraylist there rather than a counter
- 08-25-2011, 05:31 PM #27
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
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(); }
- 08-25-2011, 05:33 PM #28
Please explain why/how the for() loop control could cause the problem?
- 08-25-2011, 05:46 PM #29
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
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.
- 08-25-2011, 05:48 PM #30
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?
- 08-25-2011, 10:25 PM #31
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
using
i have being testing and still cant find the end of it, its been very tricky.Java Code:System.out.println( String.valueOf() ); or System.out.println( );
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..
- 08-25-2011, 10:28 PM #32
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)
- 08-25-2011, 10:59 PM #33
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
if this is what you mean, i have never done something like this, i have placed println in specific places to see printouts.
- 08-25-2011, 11:00 PM #34
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
how do you do this if i may ask please..
- 08-25-2011, 11:13 PM #35
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.Java Code:how do you do this
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 connectionJava 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]);
- 08-26-2011, 12:00 AM #36
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
here, for the server
and clientJava 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
is this fine?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
- 08-26-2011, 12:03 AM #37
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?
- 08-26-2011, 12:20 AM #38
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
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...
- 08-26-2011, 12:24 AM #39
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.
- 08-26-2011, 12:38 AM #40
Member
- Join Date
- Jul 2011
- Location
- kent, UK
- Posts
- 47
- Rep Power
- 0
Similar Threads
-
Voice chat with multiple chat rooms, suggestions needed
By sonofrage in forum NetworkingReplies: 4Last Post: 03-31-2011, 10:37 PM -
I have created a Java Chat Server, now where do i put it?
By lorenz82 in forum New To JavaReplies: 2Last Post: 03-21-2010, 02:31 PM -
Cannot get my JList to update!
By rangvald in forum AWT / SwingReplies: 1Last Post: 11-17-2009, 01:57 PM -
Help with Java IRC Chat Channel
By sari in forum New To JavaReplies: 1Last Post: 02-03-2009, 07:21 AM -
Java Program chat
By susan in forum Advanced JavaReplies: 1Last Post: 07-25-2007, 09:05 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks