This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Server accept both connections but print messages only from one.  RSS feed

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 3321
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried to run client class 2 times? Because it does not work for second client.
 
Norm Radder
Rancher
Posts: 3321
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This does not look right:
Why are 2 instances of ServerFrame created?
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you remove that frame won't exist.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey , i really thank you for that time you spend for helping me. But i think problem is somewhere else.
 
Norm Radder
Rancher
Posts: 3321
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still same thing, text from other clients doesn't show up.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post me the code you edited?
 
Norm Radder
Rancher
Posts: 3321
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it's still not working like it should right? :/
 
Norm Radder
Rancher
Posts: 3321
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Norm Radder
Rancher
Posts: 3321
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 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.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Norm Radder
Rancher
Posts: 3321
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Norm Radder
Rancher
Posts: 3321
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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:
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Norm Radder
Rancher
Posts: 3321
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another technique for easier testing is to preload the Scanner with Strings to return:
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Norm Radder
Rancher
Posts: 3321
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are very welcome.  I'm glad you have gotten it working.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!