Java Code Examples for org.apache.mina.transport.socket.nio.NioSocketConnector#dispose()
The following examples show how to use
org.apache.mina.transport.socket.nio.NioSocketConnector#dispose() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java From TestClient with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { //网络链接工具 NetSupport support = new NetSupport(); //创建回话链 ConversationChain chain = new ConversationChain(support); buildConversation(chain); //设置会话链 support.setConversationChain(chain); NioSocketConnector connector = new NioSocketConnector(); SocketAddress address = new InetSocketAddress("localhost", 1101); boolean isConnected = support.connect(connector, address); if(isConnected){ support.startConversation(); } support.quit(); connector.dispose(); }
Example 2
Source File: HelloTcpClient.java From mina-examples with MIT License | 6 votes |
public static void main(String[] args) { NioSocketConnector connector = new NioSocketConnector(); //TCP Connector connector.getFilterChain().addLast("logging", new LoggingFilter()); connector.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); connector.getFilterChain().addLast("mdc", new MdcInjectionFilter()); connector.setHandler(new HelloClientHandler()); IoSession session; for (;;) { try { ConnectFuture future = connector.connect(new InetSocketAddress(HOSTNAME, PORT)); future.awaitUninterruptibly(); session = future.getSession(); break; } catch (RuntimeIoException e) { System.err.println("Failed to connect."); e.printStackTrace(); } } session.getCloseFuture().awaitUninterruptibly(); connector.dispose(); }
Example 3
Source File: MinaTimeClient.java From javabase with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // 创建客户端连接器. NioSocketConnector connector = new NioSocketConnector(); connector.getFilterChain().addLast("logger", new LoggingFilter()); connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8")))); // 设置编码过滤器 connector.setConnectTimeout(30); connector.setHandler(new TimeClientHandler());// 设置事件处理器 ConnectFuture cf = connector.connect(new InetSocketAddress("127.0.0.1", 9123));// 建立连接 cf.awaitUninterruptibly();// 等待连接创建完成 cf.getSession().write("hello");// 发送消息 cf.getSession().write("quit");// 发送消息 cf.getSession().getCloseFuture().awaitUninterruptibly();// 等待连接断开 connector.dispose(); }