Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Gui freezes only when using multiple frames and 'while' socket is listening  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I've been searching for hours to solve this problem. Tested a lot of things but haven't figured it out. I hope someone here can help me.

I'm writing a Server-Client Chat application. User must be able to select what to run: Client, Server, or both. So I made a 'Launcher' Class with a JFrame.

Then I have 2 classes Clientwindow and Serverwindow wich extend an abstract class chatwindow. With that abstract class extending a JFrame.

In the Serverwindow Class there's a listening while loop:


wich starts a new thread for the client.

So far so good, but now I have a weird combination of facts...

- If I only start the Serverwindow without the Launcher: No problem
- If I try to start Serverwindow and Clientwindow at the same time: Only Serverwindow appears
- If I start Serverwindow with the Launcher (JFrame): Both frames freeze and program hangs
- If I start Serverwindow without the while loop: No problem

thanks for the help
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is very hard to know your problems without the actual code or the runnable program...
author and iconoclast
Posts: 24220
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karel,

Welcome to JavaRanch!

Roseanne is right, of course, but I can make a good guess: you put the "accept()" loop above right into an event handler of your GUI. Note that all events get handled on the same thread; by putting an infinite loop in an event handler, you prevent the GUI from ever receiving another event, and so the program appears to "freeze".

There's no way around it: you must create a dedicated thread for the server loop to run in. You probably have to do the same thing for the client, if the client sits in a loop reading and writing. Since you're apparently already creating threads to handle the server connections, this shouldn't be a problem for you.
Karel Tevarnier
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the quick reply's

I was already thinking to put the server in another thread on its own.

Here's the full program (some names are in dutch):

It's a project for school. Other people made it by starting te whole program 2 times, first selecting server and connect, second selecting client and connect.

If I should do it like them now, I'll have to rewrite the whole thing.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!