/**解压线程*/ private void deCompressFun() { while (isConnect) { try { RecPacket recPacket = recPacketQueue.Dequeue(); LZOCompressor lzoCompress = new LZOCompressor(); if (recPacket != null) { RecPacket.PacketType packetType = recPacket.getPacketType(); DifferentBitmapWithCursor difbitWithCur = new DifferentBitmapWithCursor(); difbitWithCur.setPacketType(packetType); switch (packetType) { case RecPacket.PacketType.BITMAP: difbitWithCur.setBitmapType(recPacket.getBitmapType()); difbitWithCur.setCursorPoint(recPacket.getCursorPoint()); difbitWithCur.setDifPointsList(recPacket.getDifPointsList()); byte[] dataBytes = recPacket.getBitByts(); byte[] getByte = lzoCompress.Decompress(dataBytes); Bitmap temp = (Bitmap)Bitmap.FromStream(new MemoryStream(getByte)); difbitWithCur.setDifBitmap(temp); /**放入差异队列*/ deCompressDifQueue.Enqueue(difbitWithCur); labelDif.Text = "差异队列大小:" + deCompressDifQueue.getQueueSize() + "\r\n"; break; case RecPacket.PacketType.TEXT: difbitWithCur.setStringValue(recPacket.getStringValue()); deCompressDifQueue.Enqueue(difbitWithCur); labelDif.Text = "差异队列大小:" + deCompressDifQueue.getQueueSize() + "\r\n"; break; default: break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void docker(object obj) { ThreadParam tempParam = obj as ThreadParam; TcpClient Client = tempParam.param1; int index = tempParam.param2; //Debug.Log("소켓 대기중...."); //Debug.Log("소켓 연결되었습니다."); Control_Socket.process_Stream[index] = Client.GetStream(); Control_Socket.Isconnected[index] = true; byte[] Buffer = new byte[1024]; int length = 0; while (true) { //Debug.Log("............................."); try { //Debug.Log("데이터 받는중 "); while (true) { length = Control_Socket.process_Stream[index].Read(Buffer, 0, 1023); //Debug.Log(length); RecData = ByteToStruct <RecPacket>(Buffer); Control_Socket.StoreRecData[index] = RecData; Control_Socket.IsRecStore[index] = true; Debug.Log("데이터 받음 process " + index); } } catch (Exception e) { Debug.Log(e.Message); //ocket_Threading_Flag = false; Client.Close(); Server.Stop(); continue; } } }
/**数据接收函数*/ private void recPacketFun(object clientSocket) { NetworkStream stream = new NetworkStream((Socket)clientSocket); BinaryReader reader = new BinaryReader(stream); while (isConnect) { try { RecPacket recpacket = new RecPacket(); RecPacket.PacketType packetType = (RecPacket.PacketType)reader.ReadByte(); recpacket.setPacketType(packetType); switch (packetType) { case RecPacket.PacketType.BITMAP: int bitmapBytesLen = reader.ReadInt32(); RecPacket.BitmapType type = (RecPacket.BitmapType)reader.ReadByte(); short cursorPointX = reader.ReadInt16(); short cursorpointY = reader.ReadInt16(); short difNum = reader.ReadInt16(); if (difNum > 0) { List <ShortRec> difPoints = new List <ShortRec>(); for (int i = 0; i < difNum; i++) { short xpoint = reader.ReadInt16(); short ypoint = reader.ReadInt16(); short width = reader.ReadInt16(); short height = reader.ReadInt16(); ShortRec difPoint = new ShortRec(xpoint, ypoint, width, height); difPoints.Add(difPoint); } recpacket.setDifPointsList(difPoints); } int size = 0; byte[] getBitmapBytes = new byte[bitmapBytesLen]; while (size < bitmapBytesLen) { size += reader.Read(getBitmapBytes, size, bitmapBytesLen - size); } /**组装数据*/ recpacket.setBitByts(getBitmapBytes); recpacket.setBitmapBytesLength(bitmapBytesLen); recpacket.setBitmapType(type); recpacket.setCursorPoint(new ShortPoint(cursorPointX, cursorpointY)); /**添加到接收队列*/ recPacketQueue.Enqueue(recpacket); labelQueueCap.Text = "接收队列大小:" + recPacketQueue.getQueueSize() + "\r\n"; break; case RecPacket.PacketType.TEXT: int textLen = reader.ReadInt32(); int textSize = 0; byte[] getTextBytes = new byte[textLen]; while (textSize < textLen) { textSize += reader.Read(getTextBytes, textSize, textLen - textSize); } recpacket.setStringValue(Encoding.UTF8.GetString(getTextBytes)); /**添加到接收队列*/ recPacketQueue.Enqueue(recpacket); labelQueueCap.Text = "接收队列大小:" + recPacketQueue.getQueueSize() + "\r\n"; break; default: break; } } catch (Exception ex) { MessageBox.Show(ex.Message); stopClient(); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); ErrorInfo.getErrorWriter().writeErrorMassageToFile(DateTime.Now.ToString() + ":" + ex.Message + "\r\n" + ex.StackTrace); } } }