# HG changeset patch # User e085711 # Date 1303776494 -32400 # Node ID 4881586aead9ba14203b9ea584631b4f8d170958 # Parent f9ecb0315303be83a850de140823c3cc24b9d57d succeed drawFirstimage()!! diff -r f9ecb0315303 -r 4881586aead9 src/myVncClient/MyRfbProto.java --- a/src/myVncClient/MyRfbProto.java Sun Apr 24 16:55:29 2011 +0900 +++ b/src/myVncClient/MyRfbProto.java Tue Apr 26 09:08:14 2011 +0900 @@ -1,11 +1,16 @@ package myVncClient; +import java.awt.image.BufferedImage; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.net.BindException; import java.net.ServerSocket; import java.net.Socket; import java.util.LinkedList; +import javax.imageio.ImageIO; + class MyRfbProto extends RfbProto { @@ -14,8 +19,10 @@ private int encoding; private ServerSocket servSock; + private int acceptPort; private byte initData[]; private LinkedList cliList; + byte[] pngBytes; MyRfbProto(String h, int p, VncViewer v ) throws IOException { super(h, p, v); @@ -27,9 +34,26 @@ cliList = new LinkedList (); } - void initServSock(int port) throws IOException{ servSock = new ServerSocket(port); + acceptPort = port; + } + void selectPort(){ + int i = 5550; + while(true){ + try{ + initServSock(i); + break; + }catch(BindException e){ + i++; + continue; + }catch(IOException e){ + + } + } + } + int getAcceptPort(){ + return acceptPort; } void setSoTimeout(int num) throws IOException { @@ -101,6 +125,20 @@ inNormalProtocol = true; } + void readPngData()throws IOException{ + // Dataの大きさを読み込む + int length = readU32(); + pngBytes = new byte[length]; +// skipBytes(1); +// pngBytes = new byte[is.available()]; + System.out.println("is.available()="+is.available()); + readFully(pngBytes); + } + + BufferedImage createBimg()throws IOException{ + BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(pngBytes)); + return bimg; + } void sendInitData(Socket sock) throws IOException{ sock.getOutputStream().write(initData); @@ -152,6 +190,10 @@ encoding = readU32(); reset(); } + + + + void printFramebufferUpdate(){ System.out.println("messageType=" + messageType); diff -r f9ecb0315303 -r 4881586aead9 src/myVncClient/VncCanvas.java --- a/src/myVncClient/VncCanvas.java Sun Apr 24 16:55:29 2011 +0900 +++ b/src/myVncClient/VncCanvas.java Tue Apr 26 09:08:14 2011 +0900 @@ -276,6 +276,7 @@ memGraphics = memImage.getGraphics(); } } + // Images with raw pixels should be re-allocated on every change // of geometry or pixel format. @@ -1420,9 +1421,10 @@ } } } - +/* handleUpdatedPixels(x, y, w, h); scheduleRepaint(x, y, w, h); +*/ } // @@ -1903,4 +1905,10 @@ cursorWidth, cursorHeight); } } + void drawFirstImage()throws IOException { + BufferedImage bimg = rfb.createBimg(); + memGraphics.setClip(0,0, rfb.framebufferWidth, rfb.framebufferHeight ); + memGraphics.drawImage( bimg, 0,0, null); + + } } diff -r f9ecb0315303 -r 4881586aead9 src/myVncClient/VncViewer.java --- a/src/myVncClient/VncViewer.java Sun Apr 24 16:55:29 2011 +0900 +++ b/src/myVncClient/VncViewer.java Tue Apr 26 09:08:14 2011 +0900 @@ -1,30 +1,4 @@ package myVncClient; -// -// Copyright (C) 2001-2004 HorizonLive.com, Inc. All Rights Reserved. -// Copyright (C) 2002 Constantin Kaplinsky. All Rights Reserved. -// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. -// -// This is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This software is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this software; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// - -// -// VncViewer.java - the VNC viewer applet. This class mainly just sets up the -// user interface, leaving it to the VncCanvas to do the actual rendering of -// a VNC desktop. -// import java.awt.*; import java.awt.event.*; @@ -47,10 +21,7 @@ v.mainArgs = argv; v.inAnApplet = false; v.inSeparateFrame = true; - /* - * if(argv.length > 1){ v.host = argv[0]; v.port = - * Integer.parseInt(argv[1]); } - */ + v.init(); v.start(); } @@ -159,11 +130,14 @@ } /*****************************************************************************/ - vncFrame.pack(); - vncFrame.setVisible(true); + if(inSeparateFrame) { + vncFrame.pack(); + vncFrame.setVisible(true); + } else { + validate(); + } try { - rfb = new MyRfbProto(host, port, this); rfb.readServerInit(); @@ -686,21 +660,13 @@ // void readParameters() { -// host = readParameter("HOST", !inAnApplet); - if (mainArgs.length > 0) - host = mainArgs[0]; - else - host = "hades.cr.ie.u-ryukyu.ac.jp"; - /* - * if (host == null) { host = getCodeBase().getHost(); if - * (host.equals("")) { fatalError("HOST parameter not specified"); } } - */ + host = readParameter("HOST", !inAnApplet); -// port = readIntParameter("PORT", 5550); - if (mainArgs.length > 1) - port = Integer.parseInt(mainArgs[1]); - else - port = 5550; + if (host == null) { host = getCodeBase().getHost(); if + (host.equals("")) { fatalError("HOST parameter not specified"); } } + + port = readIntParameter("PORT", 5550); + // Read "ENCPASSWORD" or "PASSWORD" parameter if specified. readPasswordParameters(); diff -r f9ecb0315303 -r 4881586aead9 src/myVncClient/acceptThread.java --- a/src/myVncClient/acceptThread.java Sun Apr 24 16:55:29 2011 +0900 +++ b/src/myVncClient/acceptThread.java Tue Apr 26 09:08:14 2011 +0900 @@ -11,6 +11,8 @@ } public void run() { + rfb.selectPort(); + while (true) { try { Socket newCli = rfb.accept();