c# - UDP - Can I send two datagram parts, and make the receiving end combine them into one? -


this maybe stupid question, since relatively new udp here goes... if having 2 separate byte arrays need receiving side 1 big array, example:

byte[] array1 = {1,1,1} byte[] array2 = {2,2,2} 

can avoid having create buffer , copy each array it, , send buffer, this:

byte[] buffer= new byte[array1.length + array2.length]; buffer.blockcopy(array1, 0, buffer, 0, array1.length); buffer.blockcopy(array2, 0, buffer, array1.length, array2.length);  udpclient.send(buffer, buffer.length); 

because if 2 big, , data rate high, copying uses system resources... can somehow tell udpclient starting udp fragmentation, , this:

udpclient.imstartingonebigdatagram();  udpclient.send(array1, array1.length); udpclient.send(array2, array2.length);  udpclient.thatsallfolks(); 

and sure receiving side get:

byte[] recv = {1,1,1,2,2,2} 

i using c# this, , dont need use udpclient, making point.

use equivalent of win32 api's wsasendmsg:

public int send(     ilist<arraysegment<byte>> buffers,     socketflags socketflags,     out socketerror errorcode ) 

http://msdn.microsoft.com/en-us/library/ms145161.aspx

but premature optimisation, if perform testing see use i/o scatter gather arrays need @ least 9kb of data performance improvement. small buffers, i.e. less page size (4kb on x86) faster build contiguous buffer before passing socket api.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -