简体   繁体   English

来自Socket c#的XmlSerializer.Deserialize()

[英]XmlSerializer.Deserialize() from Socket c#

Here is a piece of code from my application: 这是我的应用程序中的一段代码:

using (NetworkStream ns = new NetworkStream(newClientSock))
{
   XmlSerializer xs = new XmlSerializer(typeof(RSAParameters));
   xs.Serialize(ns, _publicKey);

   RSAParameters clientPubKey = (RSAParameters)xs.Deserialize(ns);
}

What im trying to do is a form of "Handshake" between two client sockets. 我试图做的是两个客户端套接字之间的“握手”形式。 Im not very familiar with serialization, so my question is, will the XmlSerializer(xs) object wait for something to be sent and then desirialize it, or the data that need to be desirialized should already be in that stream? 我对序列化不是很熟悉,所以我的问题是,XmlSerializer(xs)对象会等待要发送的内容然后对其进行反序列化,还是需要反序列化的数据应该已经在该流中?

Thanks in advance, 提前致谢,

XmlSerializer will read the stream as it arrives at your end of the socket (ie will wait). XmlSerializer将在流到达套接字末尾时读取流(即等待)。 There is no need to buffer it. 无需缓冲它。 However a common error is not to Flush the output stream at the sender end (making the deserializer at the other end wait forever). 但是,常见的错误不是在发送器端刷新输出流(使另一端的解串器永远等待)。 You should make sure you Flush it after you call Serialize(). 您应该确保在调用Serialize()之后刷新它。

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

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