繁体   English   中英

响应后Spring Integration tcp连接如何紧密

[英]how close spring integration tcp connection after response

我写一个0字节终止符的TCP服务器。 该安装程序可以双向使用,但是服务器在发送响应后不会关闭连接:

设定:

<int-ip:tcp-connection-factory id="MyServerConnectionFactory"
                           type="server"
                           port="8083"
                           serializer="MyConnectionSerializeDeserialize"
                           deserializer="MyConnectionSerializeDeserialize"
                           />
<bean id="MyConnectionSerializeDeserialize"     class="org.springframework.integration.ip.tcp.serializer.ByteArraySingleTerminatorSerializer">
        <constructor-arg type="byte" value="0" />
        <property name="maxMessageSize" value="100000"/>
</bean>


<int-ip:tcp-inbound-gateway id="MyGateway"
                        connection-factory="MyServerConnectionFactory"
                        request-channel="MyIncomingServerChannel"
                        error-channel="errorChannel"/>

<int:channel id="MyIncomingServerChannel"/>

<int:service-activator input-channel="MyIncomingServerChannel"
                   ref="MyService"
                   method="process"/>

<bean id="MyService"
  class="mypackage.MyService"/>

MyService中的代码:

   public byte[] process(byte[] input) {
        ByteArrayInputStream stream = new ByteArrayInputStream(input);
        // process the stream
    ByteArrayOutputStream outstream = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(outstream);
    pw.print("Ok");
    pw.flush();
    return outstream.toByteArray();
}

返回响应后,如何告诉框架关闭连接?

谢谢

客户端通常会在收到响应后关闭套接字,但是如果您在连接工厂上设置了single-use="true" ,则发送响应后套接字将被关闭(通常为FIN)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM