简体   繁体   English

通过我的SSL套接字发送的数据包变得非常大

[英]Data packet, when sent over my SSL Socket becomes extremely large

I have recently tried my hands over Socket Programming by creating an SSL Socket used to stream data live from a server with no success of course. 我最近尝试通过创建用于传输来自服务器的实时数据流的SSL套接字来尝试Socket编程,但是没有成功。 When I analyze the data packets through Wireshark, I realize the size of request data has been magnified n number of times in the packet and hence the request reaches the server in fragments where as the actual JSON request is a handful of bytes and should reach the server in a single shot. 当我通过Wireshark分析数据包时,我意识到请求数据的大小在数据包中被放大了n次,因此请求以碎片的形式到达服务器,而实际的JSON请求只有几个字节,应该达到一次性完成服务器。

Any help would be appreciated. 任何帮助,将不胜感激。

Wrap a BufferedOutputStream around the SSLSocket 's output stream, and don't flush it until you really gotta, which is usually not until you're about to read the reply. BufferedOutputStream包装在SSLSocket的输出流周围,直到真正了解时才刷新它,通常直到您要阅读答复时才这样做。 Otherwise you can be sending one byte at a time to the SSLSocket , which becomes one SSL message per byte, which can expand the data by more than 40x. 否则,您可以一次向SSLSocket发送一个字节,这将成为每个字节一个SSL消息,这可以将数据扩展40倍以上。

However: 然而:

the request reaches the server in fragments 请求以碎片的形式到达服务器

That can happen any time. 那可以随时发生。 The server has to be able to cope with receiving data as badly fragmented as one byte at a time. 服务器必须能够处理一次碎片严重碎片的数据。

where as the actual JSON request is a handful of bytes and should reach the server in a single shot. 实际的JSON请求只有几个字节,应该一次就可以到达服务器。

There is no such guarantee in TCP. TCP中没有这样的保证。

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

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