0
我有一個Spring應用程序,我需要實現與Apache MINA庫非常簡單的通信信道。Apache的MINA +春 - 服務器沒有運行
我的Spring應用程序正在運行,但MINA服務器沒有運行,在netstat的是此端口沒有被使用。
我跟着這個教程:http://mina.apache.org/mina-project/userguide/ch17-spring-integration/ch17-spring-integration.html
我在做什麼錯?
這是一個處理類:
public class ServerHandler extends IoHandlerAdapter {
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
cause.printStackTrace();
}
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
String str = message.toString();
if (str.trim().equalsIgnoreCase("quit")) {
session.close(true);
return;
}
Date date = new Date();
session.write(date.toString());
System.out.println("Message written...");
}
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
System.out.println("IDLE " + session.getIdleCount(status));
}
}
這是從applicationContext.xml中
一個XML配置<bean id="trapHandler" class="ServerHandler"></bean>
<bean id="snmpCodecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" />
</constructor-arg>
</bean>
<bean id="loggingFilter" class="org.apache.mina.filter.logging.LoggingFilter" />
<!-- The filter chain. -->
<bean id="filterChainBuilder" class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder">
<property name="filters">
<map>
<entry key="loggingFilter" value-ref="loggingFilter"/>
<entry key="codecFilter" value-ref="snmpCodecFilter"/>
</map>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.net.SocketAddress">
<bean class="org.apache.mina.integration.beans.InetSocketAddressEditor" />
</entry>
</map>
</property>
</bean>
<!-- The IoAcceptor which binds to port 161 -->
<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioDatagramAcceptor" init-method="bind" destroy-method="unbind">
<!--<property name="defaultLocalAddress" value="${interface.ip_address}:${interface.communication.port}" />-->
<property name="defaultLocalAddress" value=":6001" />
<property name="handler" ref="trapHandler" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
</bean>
你和春天有個你的客戶端? –