R
Ryan
Hi,
I am confused with how NetworkStream works.
My application needs to handle heavy requests sent through TCP socket
connection. I use NetworkStream.Read method to get the stream data. The
data are sent from the client servers, black boxes for my project team. But
we have an agreement to the client vendor that we exchange only fixed-length
data, say, 200 bytes per data set. A data set is a bombination of data
fields, like 56 bytes of character, followed by 4 bytes of integer, followed
by 2 bytes of characters, and so on.
I notice that the lower layer of TCP splits some packets into smaller
packets, as expected. I assumed before stream data are loaded into
NetworkStream, the smaller packets will be combined together by their
sequence number, so programmers don't need to worry about the segmentation
things of TCP stream socket. However, it seems the smaller packets are put
into the NetworkStream as soon as they are received. This causes disaster
because the only way we retrieve data sets is by the fixed length. If an
incompleted data set is read from NetworkStream, the following data sets
cannot be understood by our application.
Is it true that .NET doesn't sequence the smaller packets before they are
loaded into NetworkStream? Or do i miss something? Losts of sample codes
available on MSND and Google search, but can't find any article discussing
about this.
What could I do to sovle this problem?
Any suggestion or hint is highly appreciated!
Ryan
I am confused with how NetworkStream works.
My application needs to handle heavy requests sent through TCP socket
connection. I use NetworkStream.Read method to get the stream data. The
data are sent from the client servers, black boxes for my project team. But
we have an agreement to the client vendor that we exchange only fixed-length
data, say, 200 bytes per data set. A data set is a bombination of data
fields, like 56 bytes of character, followed by 4 bytes of integer, followed
by 2 bytes of characters, and so on.
I notice that the lower layer of TCP splits some packets into smaller
packets, as expected. I assumed before stream data are loaded into
NetworkStream, the smaller packets will be combined together by their
sequence number, so programmers don't need to worry about the segmentation
things of TCP stream socket. However, it seems the smaller packets are put
into the NetworkStream as soon as they are received. This causes disaster
because the only way we retrieve data sets is by the fixed length. If an
incompleted data set is read from NetworkStream, the following data sets
cannot be understood by our application.
Is it true that .NET doesn't sequence the smaller packets before they are
loaded into NetworkStream? Or do i miss something? Losts of sample codes
available on MSND and Google search, but can't find any article discussing
about this.
What could I do to sovle this problem?
Any suggestion or hint is highly appreciated!
Ryan