ApacheMina study notes (3)-IoService

Source: Internet
Author: User
This chapter describes the IoService of MINA-a basic class that provides all I/O services on the server and client, acts on receiving and sending messages to the peer end, manages sseions, and connections. This chapter describes the IoService of MINA-a basic class that provides all I/O services on the server and client, acts on receiving and sending messages to the peer end, manages sseions, and connections.

It is an interface implemented by IoAcceptor on the server side and implemented by IoConnector on the client side.

We will introduce this interface in the following parts:

IoService Introduction
IoService Details
IoAcceptor
IoConnector

IoService overview

IoService provides basic I/O services in the Mina framework to manage I/O Sessions. It is a key part of Mina.

For example, when you want to create a TCP server, you can write code similar to the following:

public TcpServer() throws IOException {      // Create a TCP acceptor      IoAcceptor acceptor = new NioSocketAcceptor();        // Associate the acceptor to an IoHandler instance (your application)      acceptor.setHandler(this);        // Bind : this will start the server...      acceptor.bind(new InetSocketAddress(PORT));        System.out.println("Server started...");  }

In this way, a Tcp Server is created. if you want to create a UDP server, you can change it to IoAcceptor acceptor = new niow.ramacceptor ();

To release the connection, you can call

acceptor.dispose(true)

Add a filter chain and add it to the service

// Add a logger filter  DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();  chain.addLast("logger", new LoggingFilter());    // And inject the created chain builder in the service  acceptor.setFilterChainBuilder(chain);

The above is the content of Apache Mina study Note (3)-IoService. For more information, see PHP Chinese website (www.php1.cn )!

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.