gpt4 book ai didi

java - 使用 spring 连接 apache mina

转载 作者:行者123 更新时间:2023-12-01 12:39:52 26 4
gpt4 key购买 nike

如何使用 spring mvc xml 配置 连接到 Apache Mina 中的服务器?

我的服务器中有这个配置

<bean id="trapHandler" class="com.mina.ServerHandler" />

<bean id="snmpCodecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory">
<property name="decoderMaxLineLength" value="4000"/>
</bean>
</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 8000 -->
<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor"
init-method="bind" destroy-method="unbind">
<property name="defaultLocalAddress" value=":8000" />
<property name="handler" ref="trapHandler" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
</bean>

这会将我的接受器绑定(bind)到端口 8000,对吧?在我的客户端怎么样?我如何通过端口 8000 连接到我的服务器?我如何在 xml 文件中配置 IoConnector?

最佳答案

尝试使用

<!-- The IoConnector -->
<bean id="ioConnector" class="org.apache.mina.transport.socket.nio.NioSocketConnector" init-method="connect" >
<property name="handler" ref="yourHandler" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
<property name="defaultRemoteAddress" value="localhost:8000" />
</bean>

关于java - 使用 spring 连接 apache mina,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25214905/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com