将datatable序列化后通过网络传输出现错误!求助!
VS2005我的代码如下:只贴出关键的DataBase NewDataBase = new DataBase(this.NewForm);
NewDataBase.OpenSqlConn();//打开数据库连接
byte[] ResultByte = NewDataBase.GetTable(SqlComm);
NewForm.AddInfo("发送字节数为:" + ResultByte.Length.ToString());
server.CurrentSocket.Send(ResultByte, 0, ResultByte.Length, 0);
GetTable()函数如下:部分
MemoryStream MemStream = new MemoryStream();
BinaryFormatter BF = new BinaryFormatter();
BF.Serialize(MemStream, Set1.Tables["SelectTable"]);
TableByte = MemStream.GetBuffer();
return TableByte;//TableByte是一个字节数组;
接收方:
int readcount = stream.Read(messagebyte, 0, messagebyte.Length);
BinaryFormatter BF=new BinaryFormatter ();
MemoryStream NewMemStream = new MemoryStream(messagebyte);
NewMemStream.Seek(0, SeekOrigin.Begin);?????有了这句还是提示我“在分析未完成前就到流结尾”???????
DataTable Table1 = (DataTable)BF.Deserialize(NewMemStream );
序列化后的流占用的字节数--MemStream.Length跟GetBuffer()得到的字节数组字节数不一样吗?而且,这样通过 socket发送到接收方,收到的字节数很少不完整,不能正常的还原成datatable,例如:在发送方发送的是4096字节,接收到的只有25,,请教高手哪里出错了,如何改正呢???~~~