how to send a array with socket like java 'outputstream'? can u see any demos or example serialization ? I can send a simple text with socket to my client. But how can I send array, List or Class to my client. I want to send this format List array;
Java's outputstream
can not do what you want either, all it can do is send byte[]
which is exactly what C#'s socket classes do.
If you want to send complex objects you must use some form of "Serializer" which will let you transform your objects in to a byte[]
to be sent out.
A easy to use serializer that is built in to .NET is XmlSeralizer
, this will produce a string that you can then feed in to a StreamWriter
which will convert the string to a byte[]
and write it out on to the socket. The other end would just use the reverse process using a StreamReader
.
If you do not want to use that intermediate text step I would NOT recomend using BinaryFormatter
like you see frequently on the internet, it is very "fragil" and having different levels of .NET Windows updates installed on both ends can end up breaking it. Instead I recommend using a 3rd party binary serializer like Protobuf-net