Exemplo n.º 1
0
        public VncReadMessageBody ReadServerMessage()
        {
            if (m_readingServerMessage)
            {
                return(null);
            }

            m_readingServerMessage = true;
            try
            {
                var readBody = VncComm.ReadServerMessage(m_readStream,
                                                         m_serverInitBody.ServerPixelFormat.BytesPerPixel,
                                                         m_serverInitBody.ServerPixelFormat.BigEndianFlag);

                // Set after WriteFramebufferUpdateRequest to prevent the excess data
                VncReadMessageBody retBody = null;
                var messageType            = (VncEnum.MessageTypeServerToClient)readBody[0];
                if (messageType == VncEnum.MessageTypeServerToClient.FramebufferUpdate)
                {
                    var encodeList = VncEncodeFactory.CreateVncEncodeFromBinary(readBody,
                                                                                m_serverInitBody.ServerPixelFormat.BytesPerPixel,
                                                                                m_serverInitBody.ServerPixelFormat.BigEndianFlag,
                                                                                m_zrleReader);

                    // Draw to canvas
                    lock (CanvasLock)
                    {
                        foreach (var e in encodeList)
                        {
                            // Draw to canvas
                            IVncPixelGetter pixelGetter = (e.EncodeType == VncEnum.EncodeType.ZRLE) ? m_pixelGetterZrle : m_pixelGetterNormal;
                            e.Draw(pixelGetter, m_canvas);
                        }
                    }

                    retBody = new VncReadMessageBody(messageType, encodeList, null);
                }
                else if (messageType == VncEnum.MessageTypeServerToClient.SetColorMapEntries)
                {
                    var colorMap = new VncSetColorMapEntriesBody(readBody);
                    m_pixelGetterNormal.SetColorMap(colorMap);
                    retBody = new VncReadMessageBody(messageType, null, colorMap);
                }

                onRead(new VncReadEventArgs(readBody, retBody));
                return(retBody);
            }
            catch (Exception a_ex)
            {
                cleanupForDisconnect(a_ex);
                onDisconnected(new VncCauseEventArgs(a_ex));
                return(null);
            }
            finally
            {
                m_readingServerMessage = false;
            }
        }
 public VncReadEventArgs(byte[] a_bodyRaw, VncReadMessageBody a_body)
 {
     BodyRaw = a_bodyRaw;
     Body    = a_body;
 }