• Post Reply Bookmark Topic Watch Topic
  • New Topic

got a problem in a client server chat programme.

 
praveen kumaar
Ranch Hand
Posts: 443
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i run my client and server chat programme i got a same message in a textarea infinitely times...got stuck here
someone please help...



 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Twarnit, welcome to CodeRanch!

Your code was tagged wrongly and formatted wrongly. I fixed those issues for you. Next time, please UseCodeTags and make sure you use the 'preview' button before you submit a post.
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem is caused because you don't read a new message after telling everyone about the last one.

There are some more issues with your code:
  • Your member variables are not private and final.
  • Your generic types are raw.
  • Your code is unsynchronized, leading in my case to spurious ConcurrentModificationException occurrences.
  • You're manually spawning threads. Instead, create tasks and have them executed by an ExecutorService.
  • You're not using the @Override annotation.
  • You're not initializing your GUIs on the Event Dispatch Thread.
  •  
    praveen kumaar
    Ranch Hand
    Posts: 443
    22
    Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks stephen..i have started coding around one and a half month ago..thats why you saw a that much problem in my code..

    i dont get you,can you please explain.
    dont understand "reading a new message.."
     
    Stephan van Hulst
    Bartender
    Posts: 6583
    84
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    You tell everyone about the message as long as it's not null, but the value of message never changes.
     
    praveen kumaar
    Ranch Hand
    Posts: 443
    22
    Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks stephen,i think i get you
    you meant to say reader.readline() is a varying string with time..
    and by doing this---message=reader.readLine(),the message variable will be assigned a value whatever it read first and the infinite loop keeps sending the same message again and again infinitely..
     
    Stephan van Hulst
    Bartender
    Posts: 6583
    84
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Exactly
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!