【发布时间】:2018-03-15 00:11:44
【问题描述】:
我已经实现了 TCP 套接字服务器,它接受来自客户端的传入 XML 消息。我可以通过 telnet 发送消息。
但是当我尝试通过 python 脚本建立连接并发送消息时,我得到 IOException:CRLF not found before max message length: 2048.所以我添加了 ByteArrayLengthHeaderSerializer 来序列化和反序列化,但现在我得到以下错误.
IOException:消息长度 1014132591 超过最大消息长度:2048
虽然我增加了最大消息长度,但我得到 IOException:Stream closed after 46 of 1014132591
谁能告诉我如何解决这个问题。
final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class);
ByteArrayLengthHeaderSerializer serializer = new ByteArrayLengthHeaderSerializer();
serializer.setMaxMessageSize(1000 * 1024);
crLfServer.setSerializer(serializer);
crLfServer.setDeserializer(serializer);
我已经使用 Spring Integration 实现了。下面是我的入站适配器的 sn-p
@Bean
public TcpReceivingChannelAdapter inboundAdapter(AbstractServerConnectionFactory connectionFactory) {
System.out.println("Creating inbound adapter");
TcpReceivingChannelAdapter inbound = new TcpReceivingChannelAdapter();
inbound.setConnectionFactory(connectionFactory);
//inbound.
inbound.setOutputChannel(fromTcp());
return inbound;
}
【问题讨论】:
-
您不能在服务器上使用客户端不理解的序列化程序,也不能在服务器上使用依赖于客户端未发送格式的反序列化程序。提高您的最大读取行缓冲区,或使用没有如此低限制的技术。
标签: sockets spring-boot tcp spring-integration