void ReceiveImage(int imageSize, int imageWidth, int imageHeight) { Log.Debug("Prepare to Resceive Image (size:" + imageSize + " width:" + imageWidth + " height:" + imageHeight + ")"); COMData_image image = new COMData_image(); image.imageWidth = imageWidth; image.imageHeight = imageHeight; image.data = new byte[imageSize]; int bytesReceived = 0; while (bytesReceived != imageSize) { int tmp = socket.Receive(image.data, bytesReceived, imageSize - bytesReceived, SocketFlags.None); bytesReceived += tmp; Log.Debug(bytesReceived + " bytes received so far (" + tmp + " this time) - (" + (imageSize - bytesReceived) + " left)"); } Log.Debug(bytesReceived + " bytes received"); if (imageSize == bytesReceived) { infoReceived.Enqueue(image); Log.Debug("Image Received: " + image.data.Length); RunEvent(OnReceive); } else { RunEvent(OnReceiveFailed, new SocketArgs("Image: " + imageSize + " != " + bytesReceived)); } }
void ReceiveImage(int imageSize, int imageWidth, int imageHeight) { Log.Debug(id + "|Prepare to Resceive Image (size:" + imageSize + " width:" + imageWidth + " height:" + imageHeight + ")"); COMData_image image = new COMData_image(); image.imageWidth = imageWidth; image.imageHeight = imageHeight; image.size = imageSize; image.data = imageBuffer; int bytesReceived = 0; while (bytesReceived != imageSize) { int tmp = socket.Receive(imageBuffer, bytesReceived, imageSize - bytesReceived, SocketFlags.None); bytesReceived += tmp; Log.Debug(id + "|" + bytesReceived + " bytes received so far (" + tmp + " this time) - (" + (imageSize - bytesReceived) + " left)"); } //Log.Debug(id + "|" + bytesReceived + " bytes received"); if (imageSize == bytesReceived) { server.infoReceived.Enqueue(new KeyValuePair <int, COMData>(id, image)); Log.Debug("Image Received: " + bytesReceived); RunEvent(OnReceive); } else { RunEvent(OnReceiveFailed, new SocketArgs("Image: " + imageSize + " != " + bytesReceived)); } }
bool SendImage(COMData_image image) { string header = COMData.macroInit + image.type + COMData.macroSeparator + image.data.Length + COMData.macroSeparator + image.imageWidth + COMData.macroSeparator + image.imageHeight + COMData.macroEnd; Log.Debug(header); socket.Send(System.Text.Encoding.UTF8.GetBytes(header)); int bytesSent = socket.Send(image.data); return(bytesSent == image.data.Length); }