bVNC 客户端源码分析(android)

  1. 1)登录界面
  2. 2)桌面Activity
    3)启动vnc                                                      
    4)显示桌面

  1. 1)登录界面
  2. com.iiordanov.bVNC.bVNC.java

  3. 创建登录界面(填IP,PORT等等
  4. @Override
  5. public void onCreate(Bundle icicle) {

  6.     goButton = (Button) findViewById(R.id.buttonGO);
  7.     goButton.setOnClickListener(new View.OnClickListener() {
  8.     @Override
  9.     public void onClick(View view) {
  10.         if (ipText.getText().length() != 0 && portText.getText().length() != 0)
  11.             canvasStart();
  12.         else
  13.             Toast.makeText(view.getContext(), R.string.vnc_server_empty, Toast.LENGTH_LONG).show();
  14.         }
  15.     });
  16. }



  17. private void canvasStart() {
  18.     if (selected == null) return;
  19.     MemoryInfo info = Utils.getMemoryInfo(this);
  20.     if (info.lowMemory)
  21.         System.gc();
  22.     start();
  23. }

  24. /**
  25.  * Starts the activity which makes a VNC connection and displays the remote desktop.
  26.  */
  27. private void start () {
  28.     isConnecting = true;
  29.     //从登陆界面读取数据写入bean
  30.     updateSelectedFromView();
  31.     saveAndWriteRecent();

  32.     //启动RemoteCanvasActivity, 参数为selected.Gen_getValues()
  33.     Intent intent = new Intent(this, RemoteCanvasActivity.class);
  34.     intent.putExtra(Constants.CONNECTION,selected.Gen_getValues());
  35.     startActivity(intent);
  36. }

 2)桌面Activity
  1. com.iiordanov.bVNC.RemoteCanvasActivity.java

  2. @Override
  3. public void onCreate(Bundle icicle) {
  4.     super.onCreate(icicle);
  5.     //读取bean传过来的参数
  6.     initialize();

  7.     //继续连接,也就是向VNC服务端发起连接
  8.     continueConnecting();
  9. }


  10. void continueConnecting () {

  11.     // Initialize and define actions for on-screen keys.
  12.     initializeOnScreenKeys ();

  13.     //实际发起连接
  14.     canvas.initializeCanvas(connection, database, new Runnable() {
  15.         public void run() {
  16.             try { setModes(); } catch (NullPointerException e) { }
  17.         }
  18.     });
  19. }
  20.               
  21. 3)启动vnc                                                                       
  22. com.iiordanov.bVNC.RemoteCanvas.java

  23. /**
  24.  * Create a view showing a remote desktop connection
  25.  * @param context Containing context (activity)
  26.  * @param bean Connection settings
  27.  * @param setModes Callback to run on UI thread after connection is set up
  28.  */
  29. void initializeCanvas(ConnectionBean bean, Database db, final Runnable setModes) {
  30.     
  31.     Thread t = new Thread () {
  32.         public void run() {
  33.             try {

  34.                 if (isSpice) {
  35.                     startSpiceConnection();
  36.                 } else if (isRdp) {
  37.                     startRdpConnection();
  38.                 } else if (connection.getConnectionType() < 4) {
  39.                     //启动连接
  40.                     startVncConnection();
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }

  46. /**
  47.  * Starts a VNC connection using the TightVNC backend.
  48.  * @throws Exception
  49.  */
  50. private void startVncConnection() throws Exception {
  51.     Log.i(TAG, "Connecting to: " + connection.getAddress() + ", port: " + connection.getPort());
  52.     
  53.     String address = getAddress();
  54.     int vncPort = getPort(connection.getPort());
  55.     boolean anonTLS = (connection.getConnectionType() == Constants.CONN_TYPE_ANONTLS);
  56.     try {
  57.         rfb = new RfbProto(decoder, address, vncPort,
  58.                             connection.getPrefEncoding(), connection.getViewOnly());
  59.         Log.v(TAG, "Connected to server: " + address + " at port: " + vncPort);
  60.         rfb.initializeAndAuthenticate(connection.getUserName(), connection.getPassword(),
  61.                                         connection.getUseRepeater(), connection.getRepeaterId(), anonTLS);
  62.     } catch (Exception e) {
  63.         throw new Exception (getContext().getString(R.string.error_vnc_unable_to_connect) + e.getLocalizedMessage());
  64.     }
  65.     
  66.     rfbconn = rfb;
  67.     pointer = new RemoteVncPointer (rfbconn, RemoteCanvas.this, handler);
  68.     keyboard = new RemoteVncKeyboard (rfbconn, RemoteCanvas.this, handler);
  69.     
  70.     rfb.writeClientInit();
  71.     rfb.readServerInit();
  72.     initializeBitmap (displayWidth, displayHeight);
  73.     decoder.setPixelFormat(rfb);
  74.     
  75.     handler.post(new Runnable() {
  76.         public void run() {
  77.             pd.setMessage(getContext().getString(R.string.info_progress_dialog_downloading));
  78.         }
  79.     });
  80.     
  81.     sendUnixAuth ();
  82.     if (connection.getUseLocalCursor())
  83.         initializeSoftCursor();
  84.     
  85.     handler.post(drawableSetter);
  86.     handler.post(setModes);
  87.     handler.post(desktopInfo);
  88.                                                                                                                                                           
  89.     // Hide progress dialog
  90.     if (pd.isShowing())
  91.         pd.dismiss();
  92.     
  93.     rfb.processProtocol(this, connection.getUseLocalCursor());
  94. }

  95. 4)显示桌面
  96. com.iiordanov.bVNC.RfbProto.java
  97. java实现的RFB图像显示
  98. public void processProtocol () throws Exception {

  99. }


<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(1072) | 评论(0) | 转发(0) |
0

上一篇:android DPAD

下一篇:android项目增加v7.appcompat

给主人留下些什么吧!~~
评论热议
Thank you for supporting my work and GPL open-source software by donating! Please also rate my application, and tell everyone about it! If bVNC doesn't work for you or you're unhappy, do not write a review, please post your question in the forum! https://groups.google.com/forum/#!forum/bvnc-ardp-aspice-opaque-android-bb10-clients If you need an RDP application, please search for aRDP in Google Play. In addition, a SPICE client named aSPICE is available. Finally, if you are an oVirt, RHEV, or Proxmox user, check out Opaque. bVNC is a secure, open source VNC client. Its features include: - Windows, Mac, Linux, BSD, or any other OS with a VNC server installed - Master password support in the Pro version - Multi-factor (two-factor) SSH authentication in the Pro version - Multi-touch control over the remote mouse. One finger tap left-clicks, two-finger tap right-clicks, and three-finger tap middle-clicks - Right and middle-dragging if you don't lift the first finger that tapped - Scrolling with a two-finger drag - Pinch-zoom - Force Landscape, Immersive Mode Disable, Keep Screen Awake options in Main Menu - Dynamic resolution changes, allowing you to reconfigure your desktop while connected, and control over virtual machines from BIOS to OS - Full rotation - use the central lock rotation on your device to disable rotation - Multi-language - Full mouse support - Full desktop visibility even with soft keyboard extended - SSH tunneling, AnonTLS and VeNCrypt for secure connections (does not support RealVNC encryption). - High-grade encryption superior to RDP using SSH and VeNCrypt (x509 certificates and SSL), preventing man-in-the-middle attacks - AutoX session discovery/creation similar to NX client - Tight and CopyRect encodings for quick updates - Ability to reduce the color depth over slow links - Copy/paste integration - Samsung multi-window - SSH public/private (pubkey) - Importing encrypted/unencrypted RSA keys in PEM format - Zoomable, Fit to Screen, and One to On
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kelsel

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值