I want to do communication between Client & server using GUI environment using NetBeans (socket programming). In my server I have 2 text fields and one button. I would write string data in text field and send to client by pressing button. My complete server code is given below.My button handler name is:
private void btnSentToClientActionPerformed :
I have attached the server GUI serverGUI.jpeg & my client GUI is Client GUI.jpg. My client code is:
I can send data from Server to Client. Client comes in the handler & prints “Enter1” but its printing Enter2. So its not receiving & client “display” button remains focused.
Some body please guide me why client is blocking at ds.receive()?
Solution: use a background thread to do the listening, then use EventQueue.invokeLater (or its alias SwingUtilities.invokeLater) to do any updates to the UI.
Thanks for your response. Are you talking about the following stuff:
It's useful to think of the code running on the event dispatch thread as a series of short tasks. Most tasks are invocations of event-handling methods, such as ActionListener.actionPerformed. Other tasks can be scheduled by application code, using invokeLater or invokeAndWait. Tasks on the event dispatch thread must finish quickly; if they don't, unhandled events back up and the user interface becomes unresponsive.
I am trying to understand your hint
use a background thread to do the listening, then use EventQueue.invokeLater (or its alias SwingUtilities.invokeLater) to do any updates to the UI.
You mean i have to create a thread which would do the receive operation. After receiving the data it should call EventQueue.invokeLater. am i right?
I have created the worker thread in the client program. But i dont know how it can end up unresponsiveness. My code is below: I have also added the button handler but i cant understand how the worker thread would take control jButton1ActionPerformed Method.
Some body please guide me.