Write a Java NIO socket test tool

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.