【问题标题】:Spring integration SocketException:Connection resetSpring集成SocketException:连接重置
【发布时间】:2017-08-03 15:11:14
【问题描述】:

我的服务器代码:https://stackoverflow.com/a/41765722/3871754

我的客户代码:https://alvinalexander.com/blog/post/java/simple-java-socket-client-class-program

当我运行客户端时,我会看到服务器日志:o.s.i.i.tcp.connection.TcpNetConnection : Read exception 127.0.0.1 SocketException:Connection reset

当我使用该工具对其进行测试时:https://sourceforge.net/projects/sockettest/ 然后服务器与 sockettest 应用程序正常工作,我认为这是一个客户端问题。

我该如何解决?

【问题讨论】:

    标签: java spring spring-integration spring-websocket


    【解决方案1】:

    org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory 使用 ByteArrayCrLfSerializer 反序列化客户端请求:

    /**
     * Reads data in an InputStream to a byte[]; data must be terminated by \r\n
     * (not included in resulting byte[]).
     * Writes a byte[] to an OutputStream and adds \r\n.
     *
     * @author Gary Russell
     * @since 2.0
     */
    public class ByteArrayCrLfSerializer extends AbstractPooledBufferByteArraySerializer {
    

    您应该确保您的客户端确实发送了以\r\n 终止的消息。根据示例,它不是:

    writeToAndReadFromSocket(socket, "GET /\n\n");
    

    【讨论】:

    • 如何更改服务器上的序列化程序?我想使用 ByteArrayStxEtxSerializer
    • AbstractConnectionFactory.setDeserializer()
    • 在我的例子中是 TcpNetServerConnectionFactory
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    • 2018-06-14
    • 1970-01-01
    • 2020-01-31
    相关资源
    最近更新 更多