示例#1
0
文件: VncCanvas.java 项目: mzhou/bVNC
  void doProtocolInitialisation(int dx, int dy) throws IOException {
    rfb.writeClientInit();
    rfb.readServerInit();

    initializeBitmap(dx, dy);
    decoder.setPixelFormat(rfb);
  }
示例#2
0
文件: RfbProto.java 项目: mzhou/bVNC
  public void processProtocol(VncCanvas vncCanvas, boolean useLocalCursor) throws Exception {
    boolean exitforloop = false;
    int msgType = 0;

    try {
      setEncodings(useLocalCursor);
      vncCanvas.writeFullUpdateRequest(false);

      //
      // main dispatch loop
      //
      while (maintainConnection) {
        exitforloop = false;
        if (!vncCanvas.useFull) {
          vncCanvas.syncScroll();
          // Read message type from the server.
          msgType = readServerMessageType();
          vncCanvas.doneWaiting();
        } else msgType = readServerMessageType();

        // Process the message depending on its type.
        switch (msgType) {
          case RfbProto.FramebufferUpdate:
            readFramebufferUpdate();

            for (int i = 0; i < updateNRects; i++) {
              readFramebufferUpdateRectHdr();

              switch (updateRectEncoding) {
                case RfbProto.EncodingTight:
                  decoder.handleTightRect(this, updateRectX, updateRectY, updateRectW, updateRectH);
                  break;
                case RfbProto.EncodingPointerPos:
                  vncCanvas.softCursorMove(updateRectX, updateRectY);
                  break;
                case RfbProto.EncodingXCursor:
                case RfbProto.EncodingRichCursor:
                  decoder.handleCursorShapeUpdate(
                      this, updateRectEncoding, updateRectX, updateRectY, updateRectW, updateRectH);
                  break;
                case RfbProto.EncodingLastRect:
                  exitforloop = true;
                  break;
                case RfbProto.EncodingCopyRect:
                  decoder.handleCopyRect(this, updateRectX, updateRectY, updateRectW, updateRectH);
                  break;
                case RfbProto.EncodingNewFBSize:
                  setFramebufferSize(updateRectW, updateRectH);
                  vncCanvas.updateFBSize();
                  exitforloop = true;
                  break;
                case RfbProto.EncodingRaw:
                  decoder.handleRawRect(this, updateRectX, updateRectY, updateRectW, updateRectH);
                  break;
                case RfbProto.EncodingRRE:
                  decoder.handleRRERect(this, updateRectX, updateRectY, updateRectW, updateRectH);
                  break;
                case RfbProto.EncodingCoRRE:
                  decoder.handleCoRRERect(this, updateRectX, updateRectY, updateRectW, updateRectH);
                  break;
                case RfbProto.EncodingHextile:
                  decoder.handleHextileRect(
                      this, updateRectX, updateRectY, updateRectW, updateRectH);
                  break;
                case RfbProto.EncodingZRLE:
                  decoder.handleZRLERect(this, updateRectX, updateRectY, updateRectW, updateRectH);
                  break;
                case RfbProto.EncodingZlib:
                  decoder.handleZlibRect(this, updateRectX, updateRectY, updateRectW, updateRectH);
                  break;
                default:
                  Log.e(
                      TAG,
                      "Unknown RFB rectangle encoding "
                          + updateRectEncoding
                          + " (0x"
                          + Integer.toHexString(updateRectEncoding)
                          + ")");
              }

              if (exitforloop) {
                exitforloop = false;
                break;
              }
            }

            if (decoder.isChangedColorModel()) {
              decoder.setPixelFormat(this);
              // setEncodings(useLocalCursor);
              vncCanvas.writeFullUpdateRequest(false);
            } else {
              // setEncodings(useLocalCursor);
              vncCanvas.writeFullUpdateRequest(true);
            }
            break;

          case RfbProto.SetColourMapEntries:
            throw new Exception("Can't handle SetColourMapEntries message");

          case RfbProto.Bell:
            vncCanvas.displayShortToastMessage("VNC Beep");
            break;

          case RfbProto.ServerCutText:
            vncCanvas.serverJustCutText = true;
            vncCanvas.setClipboardText(readServerCutText());
            break;

          case RfbProto.TextChat:
            // UltraVNC extension
            String msg = readTextChatMsg();
            if (msg != null && msg.length() > 0) {
              // TODO implement chat interface
            }
            break;

          default:
            throw new Exception("Unknown RFB message type " + msgType);
        }
      }
    } catch (Exception e) {
      closeSocket();
      throw e;
    } finally {
      closeSocket();
      Log.v(TAG, "Closing VNC Connection");
    }
    closeSocket();
  }