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 )!