/// <summary> /// Solicita una o varias imágenes /// </summary> /// <param name="imagesRequested">Array con las imágenes solicitadas al servidor</param> /// <returns>Array con las imágenes que retorna el servidor</returns> public Image[] RequestImages(string[] imagesRequested) { //BinaryCodec<Image> binCodImage = new BinaryCodec<Image>(); //BinaryCodec<Request> binCodReq = new BinaryCodec<Request>(); BinaryCodecRequest binCodReq = new BinaryCodecRequest(); BinaryCodecImage binCodImage = new BinaryCodecImage(); Image[] imagesReceived = new Image[imagesRequested.Length]; int position = 0; Parallel.For(0, imagesRequested.Length, new ParallelOptions { MaxDegreeOfParallelism = 4 }, (i) => { TcpClient tcpClient = Connect(); NetworkStream netStr = tcpClient.GetStream(); using (BinaryWriter bw = new BinaryWriter(netStr)) using (BinaryReader br = new BinaryReader(netStr)) { string image = imagesRequested[i]; Request request = new Request("Get image", image); byte[] sndBuffer = binCodReq.Encode(request); bw.Write(sndBuffer.Length); bw.Write(sndBuffer); int receiveBytes = br.ReadInt32(); byte[] receivedBuffer = br.ReadBytes(receiveBytes); imagesReceived[position] = binCodImage.Decode(receivedBuffer); position++; } Dispose(tcpClient); }); return(imagesReceived); }
/// <summary> /// Constructor de la clase, inicializa el codec binario /// </summary> public RequestProcessor(byte[] message) { _binaryCodec = new BinaryCodecRequest(); DecodeMessage(message); }