c# - EndianBinaryReader - Contious update of the input stream? -
I am trying to use EndianBinaryReader
and EndianBinaryWriter
Which John Skeet wrote as part of it, it works very well for the two uses used by me.
Reading before the network stream ( TCPClient
) where I read a loop reading data. I can make a single Andyen Banner Reader
and then I can settle it after application closes. By creating EndianBinaryReader
in TCPClient.GetStream
Now I'm trying to do the same thing when one reads from UdpClient But it does not have a stream because this connection is low so I get data like this
byte [] data = udpClientSnapShot.Resive (ref endpoint);
I can put this data into a memory stream
var memoryStream = new MemoryStream (data);
and then EndianBinaryReader
var endianbinaryReader = New EndianBinaryReader (new BigEndianBitConverter (), memoryStream, Encoding.ASCII) . ;
But this means that whenever I read, I have to create a new Andian Reader. ID is there a way where I can only create a stream that I can update inputstream with data from udp client?
I do not remember what Aidian Banner Reader
buffers - you Can a single memorystream
overwrite? But to be honest, there is very little overhead from an extra item here. How big are packets? (It can be cloned by memorystream
and by byte]
).
I would be tempted to use the simplest thing that works and what is an real problem is probably a change i would be using By using
(because they are IDisposable
):
using (using var memoryStream = new memorystream) (Var Andian Binirder = ..blah ..) {// use it}
Comments
Post a Comment