C# sending huge and small data buffers by socket and TCP -


i want send huge buffers (from 100mb 1gb) of data tcp. solved dividing buffer smaller (approximately 1mb buffers) , sending socket.send(). each call of socket.send() method, send part of data (smaller buffer) packed in specific structure: [start byte(1b), timestamp(4b), command(4b), length of data(4b), data send(?b), crc(1b), end byte(1b)]. works fine, when 1 huge buffer sent specific port. when try send in same time buffer data (very small, e.g. 20 bytes) using same tcp port, tcp mixed data in buffers , it's not possible decode buffer more. 'start byte' , 'end byte' in buffer not useful find start , end of buffer, because it's probable these bytes appear in data.

edit: issue not affect order or ids between packages bytes in packages. @ beginning works fine , each buffer decoded properly. after while not possible decode buffer, because contains incorrect data. looks bytes in buffer moved or changed. fields @ beginning of buffer (timestamp, command, length) contain impossible values. when want length of sent data, e.g. value -1534501133 instead of 1048556 (1048556 correct maximum size of sent data in 1 package). happens randomly connected moment when smaller independent buffer sent. additional information is, smaller buffers sent repetitively using timers , problem happens in random moments. possible send whole data (e.g. 300 mb) without problem happens rarely.

i hope, described enough.

do have suggestions how avoid problem?

tag data unique id know data relates message. also, separate packet header packet payload.

so, first request [id][packettype][time][command][length][crc]

second [id][packettype][data]

you can match ids types of packet. packet type 'header' or 'payload', header contain meta data payload allowing make sure doesnt mixed other data.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -