Click here to Skip to main content
15,888,286 members
Home / Discussions / C#
   

C#

 
QuestionDatabase migration Pin
anishkannan21-Sep-10 1:52
anishkannan21-Sep-10 1:52 
AnswerRe: Database migration Pin
Bernhard Hiller21-Sep-10 2:11
Bernhard Hiller21-Sep-10 2:11 
GeneralRe: Database migration Pin
anishkannan21-Sep-10 2:17
anishkannan21-Sep-10 2:17 
GeneralRe: Database migration Pin
anishkannan21-Sep-10 2:17
anishkannan21-Sep-10 2:17 
QuestionCheckbox List Item Value Pin
SatyaKeerthi1520-Sep-10 23:25
SatyaKeerthi1520-Sep-10 23:25 
AnswerRe: Checkbox List Item Value Pin
Henry Minute20-Sep-10 23:30
Henry Minute20-Sep-10 23:30 
QuestionHandling mouse events in off-screen rendering Pin
HalliHaida20-Sep-10 23:04
HalliHaida20-Sep-10 23:04 
QuestionReading large data with TcpClient Pin
Chesnokov Yuriy20-Sep-10 20:47
professionalChesnokov Yuriy20-Sep-10 20:47 
There is a problem with reading large TCP data transfer.

Server on one end serializes some class object with BinaryFormatter and send it to the client over TCP. Serialized object in MemoryStream may take about 2Mb in size.

In the client I've got 1Mb byte[] array to read to with asynchronous NetworkStream.BeginRead and all the data is concatenated to MemoryStream object which is used as parameter passed to every BeginRead.

If more data available to read from server NetworkStream.DataAvailable that byte[] array is added to MemoryStream, otherwise deserialization happen and MemoryStream is set to 0 length for next transfer.


The problems are:

- data sent != data recieved in size
- synchronization failure


Server sent say 1.6Mb byte[] to client.
Client gets it in chunks of upto 1Mb which are added to MemoryStream for deserialization in case NetworkStream.DataAvailable == false

1) Instead of 1.6Mb byte[] array client reads 1Mb+1Mb+1Mb+0.9Mb = 3.3Mb and deserializes correct object.

2) Sometimes after 1Mb+1Mb it gets NetworkStream.DataAvailable == false thus deserialization fails, but 3ms later it reads remaining data 1Mb+0.9Mb and deserialization is successfull

3) Sometimes after immediatly 3-5ms after 1) it gets more data from server say 1Mb+0.3Mb chunks and tries to deserialize them again with a failure of course since the data is somewhat extraneous and I do not know who is sending it

If I set to 0 length MemoryStream in case of deserialization failure 3) is handled but 2) becomes invalid.

If I do not set to 0 length MemoryStream after deserialization failure, then after 3) any other deserialization attempt will be invalid since MemoryStream will contain that extraneous data in the beggining.

Also 1Mb+1Mb+1Mb+0.9Mb might be different as 1Mb+0.3Mb+0.5Mb+0.3Mb or 1Mb+0.7Mb for the same 1.6Mb transfers from the server.
Чесноков

AnswerRe: Reading large data with TcpClient Pin
Pete O'Hanlon20-Sep-10 22:25
mvePete O'Hanlon20-Sep-10 22:25 
AnswerRe: Reading large data with TcpClient Pin
Chesnokov Yuriy21-Sep-10 0:30
professionalChesnokov Yuriy21-Sep-10 0:30 
GeneralRe: Reading large data with TcpClient Pin
Pete O'Hanlon21-Sep-10 1:21
mvePete O'Hanlon21-Sep-10 1:21 
AnswerMessage Closed Pin
21-Sep-10 1:05
stancrm21-Sep-10 1:05 
GeneralRe: Reading large data with TcpClient Pin
Chesnokov Yuriy21-Sep-10 1:37
professionalChesnokov Yuriy21-Sep-10 1:37 
GeneralRe: Reading large data with TcpClient Pin
David Knechtges21-Sep-10 3:19
David Knechtges21-Sep-10 3:19 
GeneralRe: Reading large data with TcpClient Pin
Chesnokov Yuriy21-Sep-10 3:51
professionalChesnokov Yuriy21-Sep-10 3:51 
GeneralRe: Reading large data with TcpClient Pin
Pete O'Hanlon21-Sep-10 4:44
mvePete O'Hanlon21-Sep-10 4:44 
QuestionRe: Reading large data with TcpClient Pin
Chesnokov Yuriy21-Sep-10 5:13
professionalChesnokov Yuriy21-Sep-10 5:13 
AnswerRe: Reading large data with TcpClient Pin
Pete O'Hanlon21-Sep-10 7:49
mvePete O'Hanlon21-Sep-10 7:49 
QuestionCorrect deserialization with BinaryFormatter Pin
Chesnokov Yuriy20-Sep-10 20:19
professionalChesnokov Yuriy20-Sep-10 20:19 
AnswerRe: Correct deserialization with BinaryFormatter Pin
Paw Jershauge21-Sep-10 0:35
Paw Jershauge21-Sep-10 0:35 
GeneralRe: Correct deserialization with BinaryFormatter Pin
Chesnokov Yuriy21-Sep-10 1:39
professionalChesnokov Yuriy21-Sep-10 1:39 
GeneralRe: Correct deserialization with BinaryFormatter Pin
Paw Jershauge21-Sep-10 2:18
Paw Jershauge21-Sep-10 2:18 
GeneralRe: Correct deserialization with BinaryFormatter Pin
Chesnokov Yuriy21-Sep-10 2:47
professionalChesnokov Yuriy21-Sep-10 2:47 
QuestionC# picture box Pin
C.CoderCreator20-Sep-10 20:05
C.CoderCreator20-Sep-10 20:05 
AnswerRe: C# picture box Pin
Pete O'Hanlon20-Sep-10 22:06
mvePete O'Hanlon20-Sep-10 22:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.