Compile Java NIO Socket testing tool and nio Testing Tool
In the past year, we have been exposed to some server programs written using Java NIO. The client program calls the transaction interface provided by the server by establishing a Socket connection and sending messages.
During development, you usually need to send some messages to debug the program, so you can write a tool by yourself. The tool is written in Swing to send request messages to specified IP addresses and ports and receive response messages. Very simple, but enough.
The Source Code involves the following:
(1) EDT threads and task threads in Java Swing programming perform time-consuming operations in backend task threads and update the UI when appropriate;
(2) provides a Swing interface construction method: constructing Component, loading data, and adding Listener;
(3) GridBagLayout;
(4) use TitledBorder to create controls similar to GroupBox effects;
(5) General UIUpdater class for background threads to update the UI and decouple background threads and UI Component (which can be improved );
(6) since most Swing APIs are NOT thread-safe, all UI updates are put in the EDT thread, including the code for creating the top-level JFrame in the Main function;
(7) sending and receiving messages through NIO SocketChannel;
(8) the entire message is read cyclically without knowing the message length;
Run Interface
For the source code and Jar packages, see the attachment below and provide a simple EchoServer.
Click to download