More Project 1 Hints. A bug has been discovered in the
.NET library. It is not possible to serialize to a CryptoStream
that is attached to a NetworkStream because the
Deserialize call on the receiving end of the stream will block
until the stream is closed by the sending end. You might note that all the
MSDN examples use a backing MemoryStream, so perhaps this behavior
is expected, but not documented.
A simple rule to avoid this problem is: never attach a
CryptoStream to a NetworkStream. We sketch a possible
implementation strategy:
- Use a CryptoStream attached to a MemoryStream. You
can serialize objects to this structure, then safely close the stream.
Then, get the byte array from the MemoryStream and write (or
serialize, if part of a larger object) it to the NetworkStream.
On the receiving side, reverse this process: recover the byte array,
decrypt the bytes, then deserialize the result.
Please take advantage of the additional TA office hours if you are having
difficulties with this (or any other) part of the project.