gpt4 book ai didi

java - Spring集成SocketException :Connection reset

转载 作者:行者123 更新时间:2023-11-30 06:34:12 26 4
gpt4 key购买 nike

我的服务器代码: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:读取异常 127.0.0.1 SocketException:连接重置

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

如何修复它?

最佳答案

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");

关于java - Spring集成SocketException :Connection reset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45488217/

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