[Logo]
Forums Register Login
Server accept both connections but print messages only from one.
Nothing changed in run:

run:
Server waiting for connection
New client connected.Connection accepted from Socket[addr=/127.0.0.1,port=52571,localport=5000]
Creating constructor in ServerFrameHandler
Server waiting for connection
Method handleInputMessages starts here
Message delivered from client
Actual value of msg_To_Read is This is message from first client and it will be printed in text area.
Actual value of chat_Field is :This is message from first client and it will be printed in text area.  

Method handleInputMessages ends here
Method handleInputMessages starts here
New client connected.Connection accepted from Socket[addr=/127.0.0.1,port=52572,localport=5000]
Creating constructor in ServerFrameHandler
Server waiting for connection
Method handleInputMessages starts here
Message delivered from client
Actual value of msg_To_Read is This is message from second client and it looks like everyone is ok but it doesn't show up in text area.  
Actual value of chat_Field is :This is message from second client and it looks like everyone is ok but it doesn't show up in text area.  

Method handleInputMessages ends here
Method handleInputMessages starts here
I removed the 3rd party package code and it looks like the code is working for me.   I do not have any useful GUI.
I also added some more print statements.  I also run all the classes in one JVM so their print out is in one place.  Server messages are prefixed with an S and client with a C

For debugging make the lines that are being sent short and easily understood.  For example:  line one, line two, line three

When I use those inputs I get this output:


Server waiting for connection
S New client connected.Connection accepted from Socket[addr=/127.0.0.1,port=30466,localport=5000]
C CH run()
S Creating constructor in ServerFrameHandler
Server waiting for connection
S handleInputMessages starts here
C Text message to send >line one
C Text message to send >line two
S Before value of chat_Field is :<                <<<<<<<<<< text area is empty
C Text message to send >line three
C Text message to send >exit
S Message delivered from client
S Actual value of msg_To_Read is line one
S After value of chat_Field is :line one

S Method handleInputMessages ends here
S handleInputMessages starts here
S Before value of chat_Field is :line one                  <<<<<<< first message
<
S Message delivered from client
S Actual value of msg_To_Read is line two
S After value of chat_Field is :line one
line two

S Method handleInputMessages ends here
S handleInputMessages starts here
S Before value of chat_Field is :line one           <<<<<<<<< shows 2 lines
line two
<
S Message delivered from client
S Actual value of msg_To_Read is line three
S After value of chat_Field is :line one
line two
line three

S Method handleInputMessages ends here
S handleInputMessages starts here
S Before value of chat_Field is :line one            <<<<<< shows 3 lines
line two
line three
<
S Message delivered from client
S Actual value of msg_To_Read is exit
S After value of chat_Field is :line one
line two
line three
exit

S Method handleInputMessages ends here
S handleInputMessages starts here
S Before value of chat_Field is :line one             <<<<<< shows 4 lines
line two
line three
exit
<
S Message delivered from client
S Actual value of msg_To_Read is exit
S After value of chat_Field is :line one
line two
line three
exit
exit

S Method handleInputMessages ends here
S handleInputMessages starts here

 
 

Norm Radder wrote:I removed the 3rd party package code and it looks like the code is working for me.   I do not have any useful GUI.
I also added some more print statements.  I also run all the classes in one JVM so their print out is in one place.  Server messages are prefixed with an S and client with a C

For debugging make the lines that are being sent short and easily understood.  For example:  line one, line two, line three

When I use those inputs I get this output:


Server waiting for connection
S New client connected.Connection accepted from Socket[addr=/127.0.0.1,port=30466,localport=5000]
C CH run()
S Creating constructor in ServerFrameHandler
Server waiting for connection
S handleInputMessages starts here
C Text message to send >line one
C Text message to send >line two
S Before value of chat_Field is :<                <<<<<<<<<< text area is empty
C Text message to send >line three
C Text message to send >exit
S Message delivered from client
S Actual value of msg_To_Read is line one
S After value of chat_Field is :line one

S Method handleInputMessages ends here
S handleInputMessages starts here
S Before value of chat_Field is :line one                  <<<<<<< first message
<
S Message delivered from client
S Actual value of msg_To_Read is line two
S After value of chat_Field is :line one
line two

S Method handleInputMessages ends here
S handleInputMessages starts here
S Before value of chat_Field is :line one           <<<<<<<<< shows 2 lines
line two
<
S Message delivered from client
S Actual value of msg_To_Read is line three
S After value of chat_Field is :line one
line two
line three

S Method handleInputMessages ends here
S handleInputMessages starts here
S Before value of chat_Field is :line one            <<<<<< shows 3 lines
line two
line three
<
S Message delivered from client
S Actual value of msg_To_Read is exit
S After value of chat_Field is :line one
line two
line three
exit

S Method handleInputMessages ends here
S handleInputMessages starts here
S Before value of chat_Field is :line one             <<<<<< shows 4 lines
line two
line three
exit
<
S Message delivered from client
S Actual value of msg_To_Read is exit
S After value of chat_Field is :line one
line two
line three
exit
exit

S Method handleInputMessages ends here
S handleInputMessages starts here



Thank you, yes it's working for 1 client, but when another connect text doesn't show up in chat_Field.
Have you tried to run client class 2 times? Because it does not work for second client.
This does not look right:
Why are 2 instances of ServerFrame created?
 

Norm Radder wrote:This does not look right:
Why are 2 instances of ServerFrame created?


I don't know, it's Netbeans fault. I didn't write that.
When you remove that frame won't exist.
Hey , i really thank you for that time you spend for helping me. But i think problem is somewhere else.
Get rid of all the static variables.

This is my current text area and debug output:


line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
exit : C1
exit : C2


>>>>>>>> ServerFrame constructor<<<<<<<<

Server waiting for connection
S New client connected.Connection accepted from Socket[addr=/127.0.0.1,port=30887,localport=5000]
S SFH Constructor - value of chat_Field is :<
S Creating constructor in ServerFrameHandler

Server waiting for connection
S New client connected.Connection accepted from Socket[addr=/127.0.0.1,port=30888,localport=5000]
S SFH Constructor - value of chat_Field is :<
S Creating constructor in ServerFrameHandler

Server waiting for connection
C CH run() C1
C CH run() C2
S handleInputMessages starts here
S handleInputMessages starts here
C Text message to send >line one : C1
C Text message to send >line one : C2
S Before value of chat_Field is :<
S Before value of chat_Field is :<
S After1 value of chat_Field is :line one : C1
<
S Appended value of msg_To_Read is line one : C1
S After2 value of chat_Field is :line one : C1
line one : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here
S After1 value of chat_Field is :line one : C1
line one : C2
<
S Appended value of msg_To_Read is line one : C2
S After2 value of chat_Field is :line one : C1
line one : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here
C Text message to send >line two : C1
C Text message to send >line two : C2
S Before value of chat_Field is :line one : C1
line one : C2
<
S Before value of chat_Field is :line one : C1
line one : C2
<
S After1 value of chat_Field is :line one : C1
line one : C2
line two : C1
<
S Appended value of msg_To_Read is line two : C1
S After2 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here
S After1 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
<
S Appended value of msg_To_Read is line two : C2
S After2 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here
C Text message to send >line three : C1
C Text message to send >line three : C2
S Before value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
<
S Before value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
<
S After1 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
<
S Appended value of msg_To_Read is line three : C1
S After2 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here
S After1 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
<
S Appended value of msg_To_Read is line three : C2
S After2 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here
C Text message to send >exit : C1
C Text message to send >exit : C2
S Before value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
<
S Before value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
<
S After1 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
<
S Appended value of msg_To_Read is exit : C1
S After2 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here
S After1 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
<
S Appended value of msg_To_Read is exit : C2
S After2 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here
C exited loop msg=exit : C1
C exited loop msg=exit : C2
S Before value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
<
S Before value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
<
S After1 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
exit : C1
<
S Appended value of msg_To_Read is exit : C1
S After2 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
exit : C1
exit : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here
S After1 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
exit : C1
exit : C2
<
S Appended value of msg_To_Read is exit : C2
S After2 value of chat_Field is :line one : C1
line one : C2
line two : C1
line two : C2
line three : C1
line three : C2
exit : C1
exit : C2
exit : C1
exit : C2
<
S Method handleInputMessages ends here
S handleInputMessages starts here

 
Still same thing, text from other clients doesn't show up.
Can you post me the code you edited?
Sorry, I don't post student's code very often.

The changes I made:
Removed 3rd party (netbeans) package
Add call to flush in client
Removed almost all static variables
Removed extra new instances of ServerFrame
Added unique name for each client
Added new higher level main method that called the main methods of the Server and Client classes - required Threads for each
Added lots of debug statements.
So it's still not working like it should right? :/
I don't know what "working like it should" means.  
Did you look at my post showing the contents of the textarea?  I think it showed all the messages sent from two clients.

Here's the content of the text area with 3 clients:


line one : C1
line one : C3
line one : C2
line two : C1
line two : C3
line two : C2
line three : C3
line three : C1
line three : C2
exit : C2
exit : C3
exit : C1
exit : C3
exit : C1
exit : C2

 
 

Norm Radder wrote:I don't know what "working like it should" means.  
Did you look at my post showing the contents of the textarea?  I think it showed all the messages sent from two clients.


Yes, I did. But text does NOT appear in chat_field :/
Chat_field takes new messages, chat field value changes like it should but text doesn't appear on the chat_field.
 

 text doesn't appear on the chat_field.


All the quoted text in my last post was copied from the text area the program displayed.
So i did sometimes wrong, that's why i asked for the code, it's only for learning purpouses .Its hard too me to understand when i can't see how it looks like. But if You don't want to post it its ok. THank you for all effort you put into this.
If you follow the recommendations I made:
remove static
remove extra instances of ServerFrame
flush output in client

You will  be close to having a working program.
 

Norm Radder wrote:If you follow the recommendations I made:
remove static
remove extra instances of ServerFrame

You will  be close to having a working program.


Please tell me only how to remove extra instaces of ServerFrame, i don't understand this and i think
"Added new higher level main method that called the main methods of the Server and Client classes - required Threads for each "
solves my problem.
 

how to remove extra instaces of ServerFrame


By commenting them out:


The code will need a call to setVisible() added to main()

solves my problem.


I doubt that would solve the problem.  I do it for automated testing all in one JVM.

Here is the main() method I use.  It has extra code from other client/server tests I have done:
 

Norm Radder wrote:

how to remove extra instaces of ServerFrame


By commenting them out:


The code will need a call to setVisible() added to main()


Thank you my MASTER God bless You.
Another technique for easier testing is to preload the Scanner with Strings to return:
IT IS WORKING. Oh my God, i cannot tell how much you helped me learning this. You are my best teacher of Java. Thank you ! Thank you! Thanks! For so many hours spended to teach me ! THANK YOU!!!
(1 like, 1 cow)
You are very welcome.  I'm glad you have gotten it working.

This thread has been viewed 936 times.

All times above are in ranch (not your local) time.
The current ranch time is
Dec 13, 2018 10:49:54.