Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

got a problem in a client server chat programme.

 
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...



 
Saloon Keeper
Posts: 13878
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 13878
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 491
    23
    Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Saloon Keeper
    Posts: 13878
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 491
    23
    Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Saloon Keeper
    Posts: 13878
    314
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Exactly
     
    When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
    free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
    reply
      Bookmark Topic Watch Topic
    • New Topic