I tried to send an struct over TCP but I don't know how to server can use StreamWriter to send and Client use StreamReader to read the struct. Please you give me an example about this, sorry for my question because I spent many to search this issue.
Thanks
Loading
VulpesPosted Feb 29, 2012, 5:24 AM
http://msdn.microsoft.com/en-us/library/system.io.binarywriter.aspx
http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx
You can convert the struct to a byte array, and back again, using methods in the System.Runtime.InteropServices.Marshal class.
There's some example code in this thread:
http://stackoverflow.com/questions/3278827/how-to-convert-structure-to-byte-array-in-c
Although I don't think it says so in there, I'd also decorate your struct with the following attribute:
[StructLayout(LayoutKind.Sequential)]
chau doanminhPosted Mar 1, 2012, 3:10 AM