简体   繁体   中英

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?

Thanks in advance,

XmlSerializer will read the stream as it arrives at your end of the socket (ie will wait). 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().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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