1 Replies - 208 Views - Last Post: 08 June 2020 - 09:43 AM Rate Topic: -----

#1 KC10513   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 13-October 17

Random bytes added after every n bytes

Posted 08 June 2020 - 12:55 AM

Hi all

I am working on a project that spool file from a mobile device to my server App. the file transferred is either PDF or JPG but when the transfer of the file start for some reason i get random byte added into my read chunks.
My Receive routine is Big, thus i cannot paste the whole code here but i'll try and explain it.
I have a state object that contains a buffer[16384] and a FileStream to write the received data. on the receive routine i have the EndRecieve Method[url="https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.endreceive?view=netcore-3.1"] that returns the number of bytes read.
While investigation i noticed that string "8000\r\n" get added in my file after receiving 32768 bytes, which by the way is the buffersize x2.
So i need help understanding this behavior and if possible help me solve the problem.

This post has been edited by KC10513: 08 June 2020 - 12:56 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Random bytes added after every n bytes

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7404
  • View blog
  • Posts: 24,977
  • Joined: 05-May 12

Re: Random bytes added after every n bytes

Posted 08 June 2020 - 09:43 AM

Well, if your code was folly best practices, then it would be using dependency injection. That would mean that you could derive a custom TestingFileStream class where you can set breakpoints for when those bad data gets written. With the breakpoint set, you can then go up the call stack to see where it is coming from.

On the other hand, if you were following best practices, you wouldn't have methods that exceed 25-30 lines and you would be able to post you receive code. And you would also have unit tests which would help you narrow down if those bad bytes are coming from your code and if so, which component.

My suggestion at this point is to start setting breakpoints and try to narrow down the source.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1