In the last year, a server program written using Java NiO was contacted, and the client program invokes the transaction interface provided by the service side by establishing a socket connection and sending a message.
Development usually need to send some messages to debug the program, so I wrote a tool. The tool uses swing to write, the primary role is to send a request message to the specified IP, port, and receive a response message. It's very simple, but it's enough.
The source code involves the following:
(1) The EDT thread and the task thread in Java swing programming, performing time-consuming operations in the background task thread, and updating the UI when appropriate;
(2) Provide a way to construct the Swing interface: Construct component, load data, add listener;
(3) GridBagLayout use;
(4) Use Titledborder to create a control similar to the GroupBox effect;
(5) General Uiupdater class, for background thread update UI, decoupling background thread and UI Component (can be more perfect);
(6) Because the swing API is mostly not thread-safe, all updates to the UI are put into the EDT thread, including the code that creates the top-level jframe in the main function;
(6) NIO Socketchannel send and receive messages;
(7) Without knowing the message length, the loop reads the entire message written;
Run interface
The source code and the jar package are attached below, while providing a simple echoserver.
Click to download
Write a Java NIO socket test tool