C# SslStream 与 GZipStream
是否可以在 C# 中使用 GZipStream 传递 SslStream?也就是说
GZipStream stream = new GZipStream(sslStream, CompressionMode.Compress);
stream.Write(...);
...
GZipStream stream = new GZipStream(sslStream, CompressionMode.Decompress);
stream.Read(...);
,如果可以的话,SslStream 在此之后仍处于可用状态还是应该关闭?
谢谢。
Is it possible to use GZipStream passing an SslStream in C#? i.e. can you do
GZipStream stream = new GZipStream(sslStream, CompressionMode.Compress);
stream.Write(...);
...
GZipStream stream = new GZipStream(sslStream, CompressionMode.Decompress);
stream.Read(...);
If this is possible, is the SslStream still in a useable state after this or should it be closed?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是可能的,有时可能有效,但有时也可能失败。如果您的协议始终允许您在 SSLStream 关闭之前“彻底关闭”GZipStream,那么它应该可以工作。我所说的“完全关闭”是指 GZipStream 关闭效果(压缩缓冲区的刷新)可以发生并传播到对等点。它可能会失败,因为 Ssl 允许相当激烈的闭包语义。请参阅 RFC 2246 的第 7.2.1 节。
It is possible and may sometimes work, but it also may sometimes fail. It should work if your protocol always allows you to "cleanly close" the GZipStream before the SSLStream closes. By "cleanly close" I mean that the GZipStream closure effects (the flushing of the compression buffer) can occur and propogate to the peer. It may fail because Ssl allows for rather drastic closure semantics. See section 7.2.1 of RFC 2246.
我想不出为什么不; SSL 流只会被给予字节,但这正是它所期望的。重要的是正确关闭 GZipStream,因为即使
Flush()
也不总是真正刷新(由于必须保留运行缓冲区以进行压缩)。所以:我还假设您没有读取和写入同一个 SSL 流(即,这是两个单独的示例,而不是一个示例),因为这并不听起来不太可能起作用。
I can't think why not; the SSL stream will just be given bytes, but that is what it expected anyway. The important thing is to close the
GZipStream
properly, as evenFlush()
doesn't always really flush (due to having to keep a running buffer for compression). So:I'm also assuming that you aren't reading and writing to the same SSL stream (i.e. that is two separate examples, not one example), as that doesn't sound likely to work.