I'm creating a simple chat program using sockets... I did the program using a console and it worked in console so the next thing I did is to make a graphical user interface but whenever the program reaches the code serverSocket.accept(), the GUI just hangs and I can't do anything.. do I have to run the graphical user interface and sockets on different threads?

10 Years
Discussion Span
Last Post by it2051229

Because accept blocks until it gets a connection attempt. You should be placing your network (and all other operational code) into a different thread from your GUI code, because when you attempt to perform an operation on the Event thread, the GUI will not respond until that operation is finished. And, if that operation takes a long time (or blocks) your GUI will be unresponsive until that operation finishes.


Yeah.. i've been experimenting the combination of threads and graphical user interface but i can't get it right... The very main class that runs first is the graphical user interface... then the main class will create a thread for the socket and i named it "socketThread".. but the problem is how will "socketThread" update or change a value on the main thread when a connection has been accepted or a data is received? or maybe i'm doing it wrong.. or maybe when the program starts, the main thread will run along with the socket thread at the same time but I think that's not possible... or is that possible??... hooowwwwwwwwwwwwwwwww

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.