c# - Receiving chunked data from a Socket to a single buffer -


I am trying to write a simple SNPP (Simple Network Paging Protocol) client using sockets. Except for small inconsistencies between servers, everything works well.

When I send a command, I will have to read the answers, which is usually a part of the data, however, Sprint's SNPP server sends answers in two parts. The first part of the data is the first digit of the status code. The second part is left, for example, when I try to get the answer "220 Gateway Ready", then it comes like this:

  2  
< P> I have to send another empty command to rest:

  20 gateway ready  

Currently, I'm using:

  byte [] buffer = new byte [256]; Socket.Receive (buffer);  

How can I ensure that I can get all the available data after issuing an order without assigning a separate buffer for each part of the data?

For the selected responses, I recommend you read the data like this:

Using
  (var resultStream = new MemoryStream ()) {integer CHUNK_SIZE = 2 * 1024; // 2KB, can be anything that fits your needs byte [] buffer = new byte [CHUNK_SIZE]; Receive int bytes; While (bytes rac = socket .recev (buffer, buffer length, socketflags, non)) gt; 0) byte [] real = new byte [bytes rexide]; Buffer Blackcopy (buffer, 0, actual, 0, bytes received); the resulting. Write (actual, 0, real. Length); } // Do something with the result, like stream, result stream. ToEre () ...}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -