/**数据接收函数*/ 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); } } }
/** * 控制扫描块的大小,块越大,扫描速度越快,但是发送的数据量就越大; * 块越小,扫描速度就越慢,但是发送的数据量就小; * 局域网一般100*100 * 广域网一般40*40 或 20*20 * 是否需要协商块的大小????进一步实验决定。默认的事30*30, * 现在已经完全由server决定,client不需要blocksize **/ //private static Size bitCmpSize = new Size(30, 30); /**图形恢复函数*/ private void recoverBitmapFun() { while (isConnect) { try { DifferentBitmapWithCursor difbitWithCur = deCompressDifQueue.Dequeue(); if (difbitWithCur != null) { RecPacket.PacketType packetType = difbitWithCur.getPacketType(); BitmapWithCursor bitmapWithCursor = new BitmapWithCursor(); bitmapWithCursor.setPacketType(packetType); switch (packetType) { case RecPacket.PacketType.BITMAP: RecPacket.BitmapType type = difbitWithCur.getBitmapType(); ShortPoint cursorpoint = difbitWithCur.getCursorPoint(); Bitmap btm = difbitWithCur.getDifBitmap(); List <ShortRec> difPoints = difbitWithCur.getDifPointsList(); switch (type) { case RecPacket.BitmapType.BLOCK: //Stopwatch sw = new Stopwatch(); //sw.Start(); Bitmap recBitmap = RecoverBitmap.recoverScreenBitmap(difPoints, globalCompareBitmap, btm /*, bitCmpSize*/); //sw.Stop(); //Console.WriteLine("client:"+sw.ElapsedMilliseconds+"ms"); bitmapWithCursor.setCursorPoint(cursorpoint); bitmapWithCursor.setScreenBitmap(recBitmap); globalCompareBitmap = (Bitmap)recBitmap.Clone(); /**放到显示队列*/ displayQueue.Enqueue(bitmapWithCursor); break; case RecPacket.BitmapType.COMPLETE: updateKeyFrame(btm, cursorpoint); break; default: break; } labeldispalyQueue.Text = "显示队列大小:" + displayQueue.getQueueSize() + "\r\n"; break; case RecPacket.PacketType.TEXT: bitmapWithCursor.setStringValue(difbitWithCur.getStringValue()); displayQueue.Enqueue(bitmapWithCursor); labeldispalyQueue.Text = "显示队列大小:" + displayQueue.getQueueSize() + "\r\n"; break; default: break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public void setBitmapType(RecPacket.BitmapType type) { this.type = type; }