daily pastebin goal
81%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. for(int ix = 0; ix < 20; ix++)
  2. {
  3.     var socket = new Socket(AddressFamily.InterNetwork,
  4.                             SocketType.Dgram, ProtocolType.Udp);
  5.     socket.Bind(new IPEndPoint(IPAddress.Any, ix+6000));
  6.     var e = new SocketAsyncEventArgs();
  7.     e.Completed+=OnReceive;
  8.     e.SetBuffer(buffer, ix*1024*1024, 1024*1024);
  9.     socket.ReceiveFromAsync(e);
  10.     _sockets.Add(socket);
  11. }
  12.    
  13. static void OnReceive(object sender, SocketAsyncEventArgs e)
  14. {
  15.     Console.WriteLine("Received {0} bytes", e.BytesTransfered);
  16.     if(!((Socket)sender).ReceiveFromAsync(e))
  17.         e_Completed(sender, e);
  18. }
  19.    
  20. private static BlockingCollection<byte[]> _received = new ...
  21.  
  22. static void OnReceive(object sender, SocketAsyncEventArgs e) {
  23.     byte[] data = new byte[e.BytesTransfered];
  24.     Array.Copy(e.buffer, e.Offset, data, 0, e.BytesTransfered);
  25.     _received.Add(data)
  26.     ...
  27. }
  28.    
  29. var parallelOptions = new ParalellOptions { MaxDegreeOfParallelism = 3 };
  30. Parallel.ForEach(_received.GetConsumingPartitioner(),
  31.                 parallelOptions,
  32.                 data => {
  33.                     // do processing
  34.                     ...
  35.                 });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top