annotate src/treeVnc/RfbProto.java @ 5:970d5ac80256

add MyDataInputStream.java and DataInputStream1.java
author one
date Mon, 23 Apr 2012 21:10:23 +0900
parents 657c691c2936
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 package treeVnc;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
2
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // Copyright (C) 2001-2004 HorizonLive.com, Inc. All Rights Reserved.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // Copyright (C) 2001-2006 Constantin Kaplinsky. All Rights Reserved.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 // This is free software; you can redistribute it and/or modify
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // it under the terms of the GNU General Public License as published by
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 // the Free Software Foundation; either version 2 of the License, or
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 // (at your option) any later version.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 // This software is distributed in the hope that it will be useful,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 // GNU General Public License for more details.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 // You should have received a copy of the GNU General Public License
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 // along with this software; if not, write to the Free Software
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 // USA.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 // RfbProto.java
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 import java.io.*;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 import java.awt.event.*;
4
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
31 import java.net.DatagramSocket;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
32 import java.net.InetSocketAddress;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 import java.net.Socket;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
34 import java.net.SocketException;
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
35 import java.nio.ByteBuffer;
4
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
36 import java.nio.channels.DatagramChannel;
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
37 import java.nio.channels.SelectionKey;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
38 import java.nio.channels.ServerSocketChannel;
4
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
39 import java.nio.channels.SocketChannel;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
40 import java.nio.channels.spi.AbstractSelector;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
41 import java.nio.channels.spi.SelectorProvider;
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
42 import java.util.LinkedList;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 import java.util.zip.*;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
45 public class RfbProto {
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 final static String versionMsg_3_3 = "RFB 003.003\n",
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
48 versionMsg_3_7 = "RFB 003.007\n", versionMsg_3_8 = "RFB 003.008\n",
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
49 versionMsg_3_855 = "RFB 003.855\n";
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 // Vendor signatures: standard VNC/RealVNC, TridiaVNC, and TightVNC
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 final static String StandardVendor = "STDV", TridiaVncVendor = "TRDV",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 TightVncVendor = "TGHT";
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 // Security types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 final static int SecTypeInvalid = 0, SecTypeNone = 1, SecTypeVncAuth = 2,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 SecTypeTight = 16;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 // Supported tunneling types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 final static int NoTunneling = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 final static String SigNoTunneling = "NOTUNNEL";
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 // Supported authentication types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 final static int AuthNone = 1, AuthVNC = 2, AuthUnixLogin = 129;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 final static String SigAuthNone = "NOAUTH__", SigAuthVNC = "VNCAUTH_",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 SigAuthUnixLogin = "ULGNAUTH";
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 // VNC authentication results
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 final static int VncAuthOK = 0, VncAuthFailed = 1, VncAuthTooMany = 2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 // Standard server-to-client messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 final static int FramebufferUpdate = 0, SetColourMapEntries = 1, Bell = 2,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 ServerCutText = 3;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
74
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 // Check Delay Top form Bottom
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 final static int CheckDelay = 11;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 // Non-standard server-to-client messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 final static int EndOfContinuousUpdates = 150;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 final static String SigEndOfContinuousUpdates = "CUS_EOCU";
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 // Standard client-to-server messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 final static int SetPixelFormat = 0, FixColourMapEntries = 1,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 SetEncodings = 2, FramebufferUpdateRequest = 3, KeyboardEvent = 4,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 PointerEvent = 5, ClientCutText = 6;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 // Non-standard client-to-server messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 final static int EnableContinuousUpdates = 150;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 final static String SigEnableContinuousUpdates = "CUC_ENCU";
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 // Supported encodings and pseudo-encodings
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 final static int EncodingRaw = 0, EncodingCopyRect = 1, EncodingRRE = 2,
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
93 EncodingCoRRE = 4, EncodingHextile = 5, EncodingZlib = 6,
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 EncodingTight = 7, EncodingZRLEE = 15, EncodingZRLE = 16,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 EncodingCompressLevel0 = 0xFFFFFF00,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 EncodingQualityLevel0 = 0xFFFFFFE0, EncodingXCursor = 0xFFFFFF10,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 EncodingRichCursor = 0xFFFFFF11, EncodingPointerPos = 0xFFFFFF18,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 EncodingLastRect = 0xFFFFFF20, EncodingNewFBSize = 0xFFFFFF21;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 final static String SigEncodingRaw = "RAW_____",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 SigEncodingCopyRect = "COPYRECT", SigEncodingRRE = "RRE_____",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 SigEncodingCoRRE = "CORRE___", SigEncodingHextile = "HEXTILE_",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 SigEncodingZlib = "ZLIB____", SigEncodingTight = "TIGHT___",
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
103 SigEncodingZRLEE = "ZRLEE___", SigEncodingZRLE = "ZRLE____",
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 SigEncodingCompressLevel0 = "COMPRLVL",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 SigEncodingQualityLevel0 = "JPEGQLVL",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 SigEncodingXCursor = "X11CURSR",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 SigEncodingRichCursor = "RCHCURSR",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 SigEncodingPointerPos = "POINTPOS",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 SigEncodingLastRect = "LASTRECT",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 SigEncodingNewFBSize = "NEWFBSIZ";
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 final static int MaxNormalEncoding = 255;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 // Contstants used in the Hextile decoder
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 final static int HextileRaw = 1, HextileBackgroundSpecified = 2,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 HextileForegroundSpecified = 4, HextileAnySubrects = 8,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 HextileSubrectsColoured = 16;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 // Contstants used in the Tight decoder
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 final static int TightMinToCompress = 12;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 final static int TightExplicitFilter = 0x04, TightFill = 0x08,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 TightJpeg = 0x09, TightMaxSubencoding = 0x09,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 TightFilterCopy = 0x00, TightFilterPalette = 0x01,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 TightFilterGradient = 0x02;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
126 static AbstractSelector selector;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 String host;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 int port;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 Socket sock;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 OutputStream os;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 SessionRecorder rec;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 boolean inNormalProtocol = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 VncViewer viewer;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 MyVncClient myVncClient;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 // Input stream is declared private to make sure it can be accessed
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 // only via RfbProto methods. We have to do this because we want to
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 // count how many bytes were read.
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
139 // private DataInputStream is;
5
970d5ac80256 add MyDataInputStream.java and DataInputStream1.java
one
parents: 4
diff changeset
140 protected MyDataInputStream is;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
141 // private long numBytesRead = 0;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 protected long numBytesRead = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 public long getNumBytesRead() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 return numBytesRead;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 // Java on UNIX does not call keyPressed() on some keys, for example
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 // swedish keys To prevent our workaround to produce duplicate
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 // keypresses on JVMs that actually works, keep track of if
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 // keyPressed() for a "broken" key was called or not.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 boolean brokenKeyPressed = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 // This will be set to true on the first framebuffer update
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 // containing Zlib-, ZRLE- or Tight-encoded data.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 boolean wereZlibUpdates = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 // This will be set to false if the startSession() was called after
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 // we have received at least one Zlib-, ZRLE- or Tight-encoded
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 // framebuffer update.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 boolean recordFromBeginning = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 // This fields are needed to show warnings about inefficiently saved
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 // sessions only once per each saved session file.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 boolean zlibWarningShown;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 boolean tightWarningShown;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 // Before starting to record each saved session, we set this field
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 // to 0, and increment on each framebuffer update. We don't flush
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 // the SessionRecorder data into the file before the second update.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 // This allows us to write initial framebuffer update with zero
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 // timestamp, to let the player show initial desktop before
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 // playback.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 int numUpdatesInSession;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 // Measuring network throughput.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 boolean timing;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 long timeWaitedIn100us;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 long timedKbits;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 // Protocol version and TightVNC-specific protocol options.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 int serverMajor, serverMinor;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 int clientMajor, clientMinor;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 boolean protocolTightVNC;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 CapsContainer tunnelCaps, authCaps;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 CapsContainer serverMsgCaps, clientMsgCaps;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 CapsContainer encodingCaps;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 // If true, informs that the RFB socket was closed.
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
190 // private boolean closed;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 protected boolean closed;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
192
1
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
193 private byte[] broadCastBuf = new byte[64000];
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 // Constructor. Make TCP connection to RFB server.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 RfbProto(String h, int p, VncViewer v) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 viewer = v;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 host = h;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 port = p;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 if (viewer.socketFactory == null) {
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
204 sock = newSocket(host, port);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 try {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 Class factoryClass = Class.forName(viewer.socketFactory);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 SocketFactory factory = (SocketFactory) factoryClass
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 .newInstance();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 if (viewer.inAnApplet)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 sock = factory.createSocket(host, port, viewer);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 else
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 sock = factory.createSocket(host, port, viewer.mainArgs);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 } catch (Exception e) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 e.printStackTrace();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 throw new IOException(e.getMessage());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 }
5
970d5ac80256 add MyDataInputStream.java and DataInputStream1.java
one
parents: 4
diff changeset
219 is = new DataInputStream1(new BufferedInputStream(sock.getInputStream(),
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 16384));
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 os = sock.getOutputStream();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 timing = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 timeWaitedIn100us = 5;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 timedKbits = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 }
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
227
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 RfbProto(String h, int p) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 host = h;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 port = p;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
232 sock = newSocket(host, port);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233
5
970d5ac80256 add MyDataInputStream.java and DataInputStream1.java
one
parents: 4
diff changeset
234 is = new DataInputStream1(new BufferedInputStream(sock.getInputStream(),
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 16384));
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 os = sock.getOutputStream();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 timing = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 timeWaitedIn100us = 5;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 timedKbits = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
4
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
243 private Socket newSocket(String host, int port) throws IOException {
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
244 SocketChannel ssChannel = SelectorProvider.provider().openSocketChannel();
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
245 ssChannel.socket().setReuseAddress(true);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
246 // this should work for IPv6/IPv4 dual stack
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
247 // check this using netstat -an result tcp46.
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
248 try {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
249 InetSocketAddress address = new InetSocketAddress(host, port);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
250 ssChannel.socket().bind(address);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
251 } catch (SocketException e) {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
252 // for some bad IPv6 implementation
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
253 ssChannel.socket().bind(new InetSocketAddress(port));
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
254 }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
255 ssChannel.configureBlocking(false);
4
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
256 ssChannel.register(selector, SelectionKey.OP_READ, new ReadtHandler(this, ssChannel));
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
257 return ssChannel.socket();
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
258 }
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
259
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
260 public DatagramSocket newDatagramSocket(String host, int port) throws IOException {
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
261 DatagramChannel ssChannel = SelectorProvider.provider().openDatagramChannel();
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
262 ssChannel.socket().setReuseAddress(true);
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
263 // this should work for IPv6/IPv4 dual stack
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
264 // check this using netstat -an result tcp46.
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
265 try {
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
266 InetSocketAddress address = new InetSocketAddress(host, port);
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
267 ssChannel.socket().bind(address);
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
268 } catch (SocketException e) {
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
269 // for some bad IPv6 implementation
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
270 ssChannel.socket().bind(new InetSocketAddress(port));
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
271 }
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
272 ssChannel.configureBlocking(false);
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
273 ssChannel.register(selector, SelectionKey.OP_READ, new ReadtHandler(this, ssChannel));
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
274 return ssChannel.socket();
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
275 }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
277 public RfbProto() {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
278
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
279 }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
280
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
281 public void initOnce() throws IOException {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
282 selector = SelectorProvider.provider().openSelector();
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
283 }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
284
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
285 public void changeRfbProto(String h, int port) throws IOException {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
286 host = h;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
287 sock = null;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
288 sock = newSocket(host, port);
5
970d5ac80256 add MyDataInputStream.java and DataInputStream1.java
one
parents: 4
diff changeset
289 is = new DataInputStream1(new BufferedInputStream(sock.getInputStream(),
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
290 16384));
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
291 os = sock.getOutputStream();
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
292
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
293 timing = false;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
294 timeWaitedIn100us = 5;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
295 timedKbits = 0;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
296 }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 synchronized void close() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 try {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 sock.close();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 closed = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 System.out.println("RFB socket closed");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 rec.close();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 rec = null;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 } catch (Exception e) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 e.printStackTrace();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 synchronized boolean closed() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 return closed;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 // Read server's protocol version message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 void readVersionMsg() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 byte[] b = new byte[12];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 readFully(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 throw new Exception("Host " + host + " port " + port
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 + " is not an RFB server");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 serverMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 serverMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 if (serverMajor < 3) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 throw new Exception(
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 "RFB server does not support protocol version 3");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 // Write our protocol version message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 void writeVersionMsg() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 clientMajor = 3;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 if (serverMajor > 3 || serverMinor >= 8) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 clientMinor = 8;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 os.write(versionMsg_3_8.getBytes());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 } else if (serverMinor >= 7) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 clientMinor = 7;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 os.write(versionMsg_3_7.getBytes());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 clientMinor = 3;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 os.write(versionMsg_3_3.getBytes());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 protocolTightVNC = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 initCapabilities();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 }
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
363
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 // Negotiate the authentication scheme.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 int negotiateSecurity() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 return (clientMinor >= 7) ? selectSecurityType() : readSecurityType();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 // Read security type from the server (protocol version 3.3).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 int readSecurityType() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 int secType = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 switch (secType) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 case SecTypeInvalid:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 readConnFailedReason();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 return SecTypeInvalid; // should never be executed
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 case SecTypeNone:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 case SecTypeVncAuth:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 return secType;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 default:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 throw new Exception("Unknown security type from RFB server: "
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 + secType);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 // Select security type from the server's list (protocol versions 3.7/3.8).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 int selectSecurityType() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 int secType = SecTypeInvalid;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 // Read the list of secutiry types.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 int nSecTypes = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 if (nSecTypes == 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 readConnFailedReason();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 return SecTypeInvalid; // should never be executed
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 byte[] secTypes = new byte[nSecTypes];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 readFully(secTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 // Find out if the server supports TightVNC protocol extensions
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 for (int i = 0; i < nSecTypes; i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 if (secTypes[i] == SecTypeTight) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 protocolTightVNC = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 os.write(SecTypeTight);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 return SecTypeTight;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 // Find first supported security type.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 for (int i = 0; i < nSecTypes; i++) {
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
419 // if (secTypes[i] == SecTypeNone || secTypes[i] == SecTypeVncAuth)
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
420 // {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
421 if (secTypes[i] == SecTypeNone || secTypes[i] == SecTypeVncAuth
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
422 || secTypes[i] == MyRfbProtoProxy.SecTypeReqAccess) {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
423 secType = secTypes[i];
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 }
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
426 }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 if (secType == SecTypeInvalid) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 throw new Exception("Server did not offer supported security type");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 os.write(secType);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 return secType;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 // Perform "no authentication".
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 void authenticateNone() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 if (clientMinor >= 8)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 readSecurityResult("No authentication");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 // Perform standard VNC Authentication.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 void authenticateVNC(String pw) throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 byte[] challenge = new byte[16];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 readFully(challenge);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 if (pw.length() > 8)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 pw = pw.substring(0, 8); // Truncate to 8 chars
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 // Truncate password on the first zero byte.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 int firstZero = pw.indexOf(0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 if (firstZero != -1)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 pw = pw.substring(0, firstZero);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 byte[] key = { 0, 0, 0, 0, 0, 0, 0, 0 };
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 System.arraycopy(pw.getBytes(), 0, key, 0, pw.length());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 DesCipher des = new DesCipher(key);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 des.encrypt(challenge, 0, challenge, 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 des.encrypt(challenge, 8, challenge, 8);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 os.write(challenge);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 readSecurityResult("VNC authentication");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 // Read security result.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 // Throws an exception on authentication failure.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 void readSecurityResult(String authType) throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 int securityResult = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 switch (securityResult) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 case VncAuthOK:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 System.out.println(authType + ": success");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 case VncAuthFailed:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 if (clientMinor >= 8)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 readConnFailedReason();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 throw new Exception(authType + ": failed");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 case VncAuthTooMany:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 throw new Exception(authType + ": failed, too many tries");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 default:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 throw new Exception(authType + ": unknown result " + securityResult);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 // Read the string describing the reason for a connection failure,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 // and throw an exception.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 void readConnFailedReason() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 int reasonLen = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 byte[] reason = new byte[reasonLen];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 readFully(reason);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 throw new Exception(new String(reason));
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 // Initialize capability lists (TightVNC protocol extensions).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 void initCapabilities() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 tunnelCaps = new CapsContainer();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 authCaps = new CapsContainer();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 serverMsgCaps = new CapsContainer();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 clientMsgCaps = new CapsContainer();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 encodingCaps = new CapsContainer();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 // Supported authentication methods
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 authCaps.add(AuthNone, StandardVendor, SigAuthNone, "No authentication");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 authCaps.add(AuthVNC, StandardVendor, SigAuthVNC,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 "Standard VNC password authentication");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 // Supported non-standard server-to-client messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 // [NONE]
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 // Supported non-standard client-to-server messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 // [NONE]
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 // Supported encoding types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 encodingCaps.add(EncodingCopyRect, StandardVendor, SigEncodingCopyRect,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 "Standard CopyRect encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 encodingCaps.add(EncodingRRE, StandardVendor, SigEncodingRRE,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 "Standard RRE encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 encodingCaps.add(EncodingCoRRE, StandardVendor, SigEncodingCoRRE,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 "Standard CoRRE encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 encodingCaps.add(EncodingHextile, StandardVendor, SigEncodingHextile,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 "Standard Hextile encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 encodingCaps.add(EncodingZRLE, StandardVendor, SigEncodingZRLE,
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
542 "Standard ZRLE encoding");
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 encodingCaps.add(EncodingZRLEE, StandardVendor, SigEncodingZRLEE,
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
544 "Standard ZRLE(E) encoding");
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 encodingCaps.add(EncodingZlib, TridiaVncVendor, SigEncodingZlib,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 "Zlib encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 encodingCaps.add(EncodingTight, TightVncVendor, SigEncodingTight,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 "Tight encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 // Supported pseudo-encoding types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 encodingCaps.add(EncodingCompressLevel0, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 SigEncodingCompressLevel0, "Compression level");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 encodingCaps.add(EncodingQualityLevel0, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 SigEncodingQualityLevel0, "JPEG quality level");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 encodingCaps.add(EncodingXCursor, TightVncVendor, SigEncodingXCursor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 "X-style cursor shape update");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 encodingCaps.add(EncodingRichCursor, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 SigEncodingRichCursor, "Rich-color cursor shape update");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 encodingCaps.add(EncodingPointerPos, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 SigEncodingPointerPos, "Pointer position update");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 encodingCaps.add(EncodingLastRect, TightVncVendor, SigEncodingLastRect,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 "LastRect protocol extension");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 encodingCaps.add(EncodingNewFBSize, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 SigEncodingNewFBSize, "Framebuffer size change");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
566
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 // Setup tunneling (TightVNC protocol extensions)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 void setupTunneling() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 int nTunnelTypes = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 if (nTunnelTypes != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 readCapabilityList(tunnelCaps, nTunnelTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 // We don't support tunneling yet.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 writeInt(NoTunneling);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 // Negotiate authentication scheme (TightVNC protocol extensions)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 int negotiateAuthenticationTight() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 int nAuthTypes = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 if (nAuthTypes == 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 return AuthNone;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 readCapabilityList(authCaps, nAuthTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 for (int i = 0; i < authCaps.numEnabled(); i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 int authType = authCaps.getByOrder(i);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 if (authType == AuthNone || authType == AuthVNC) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 writeInt(authType);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 return authType;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 throw new Exception("No suitable authentication scheme found");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 // Read a capability list (TightVNC protocol extensions)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 void readCapabilityList(CapsContainer caps, int count) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 int code;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 byte[] vendor = new byte[4];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 byte[] name = new byte[8];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 for (int i = 0; i < count; i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 code = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 readFully(vendor);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 readFully(name);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 caps.enable(new CapabilityInfo(code, vendor, name));
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 // Write a 32-bit integer into the output stream.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 void writeInt(int value) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 byte[] b = new byte[4];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 b[0] = (byte) ((value >> 24) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 b[1] = (byte) ((value >> 16) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 b[2] = (byte) ((value >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 b[3] = (byte) (value & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 // Write the client initialisation message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 void writeClientInit() throws IOException {
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
637 /*
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
638 * if (viewer.options.shareDesktop) {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
639 */
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
640
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 /**
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 * shared flag
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 */
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
644 os.write(1);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
645 // os.write(0);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
647 // viewer.options.disableShareDesktop();
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 // Read the server initialisation message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 String desktopName;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 int framebufferWidth, framebufferHeight;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 int bitsPerPixel, depth;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 boolean bigEndian, trueColour;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 int redMax, greenMax, blueMax, redShift, greenShift, blueShift;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
659
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 void readServerInit() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 framebufferWidth = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 framebufferHeight = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 bitsPerPixel = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 depth = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 bigEndian = (readU8() != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 trueColour = (readU8() != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 redMax = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 greenMax = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 blueMax = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 redShift = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 greenShift = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 blueShift = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 byte[] pad = new byte[3];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 readFully(pad);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 int nameLength = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 byte[] name = new byte[nameLength];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 readFully(name);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 desktopName = new String(name);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 // Read interaction capabilities (TightVNC protocol extensions)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 if (protocolTightVNC) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 int nServerMessageTypes = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 int nClientMessageTypes = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 int nEncodingTypes = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
687 readCapabilityList(serverMsgCaps, nServerMessageTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 readCapabilityList(clientMsgCaps, nClientMessageTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 readCapabilityList(encodingCaps, nEncodingTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
690 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
692 inNormalProtocol = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
694
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 // Create session file and write initial protocol messages into it.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 void startSession(String fname) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 rec = new SessionRecorder(fname);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 rec.writeHeader();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 rec.write(versionMsg_3_3.getBytes());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 rec.writeIntBE(SecTypeNone);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 rec.writeShortBE(framebufferWidth);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 rec.writeShortBE(framebufferHeight);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 byte[] fbsServerInitMsg = { 32, 24, 0, 1, 0, (byte) 0xFF, 0,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 (byte) 0xFF, 0, (byte) 0xFF, 16, 8, 0, 0, 0, 0 };
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 rec.write(fbsServerInitMsg);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 rec.writeIntBE(desktopName.length());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 rec.write(desktopName.getBytes());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 numUpdatesInSession = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 // FIXME: If there were e.g. ZRLE updates only, that should not
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 // affect recording of Zlib and Tight updates. So, actually
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
715 // we should maintain separate flags for Zlib, ZRLE and
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 // Tight, instead of one ``wereZlibUpdates'' variable.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 if (wereZlibUpdates)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 recordFromBeginning = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 zlibWarningShown = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 tightWarningShown = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 // Close session file.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 void closeSession() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 rec.close();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 rec = null;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 // Set new framebuffer size
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 void setFramebufferSize(int width, int height) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 framebufferWidth = width;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 framebufferHeight = height;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746 // Read the server message type
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 int readServerMessageType() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 int msgType = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 // If the session is being recorded:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 if (msgType == Bell) { // Save Bell messages in session files.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 rec.writeByte(msgType);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 if (numUpdatesInSession > 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 rec.flush();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 return msgType;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 // Read a FramebufferUpdate message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 int updateNRects;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 void readFramebufferUpdate() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 skipBytes(1);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 updateNRects = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 // System.out.println(updateNRects);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 // If the session is being recorded:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 rec.writeByte(FramebufferUpdate);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 rec.writeByte(0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 rec.writeShortBE(updateNRects);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 numUpdatesInSession++;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 // Read a FramebufferUpdate rectangle header
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 int updateRectX, updateRectY, updateRectW, updateRectH, updateRectEncoding;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 void readFramebufferUpdateRectHdr() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 updateRectX = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 updateRectY = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 updateRectW = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 updateRectH = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 updateRectEncoding = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 // System.out.println("readU16&32");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 if (updateRectEncoding == EncodingZlib
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 || updateRectEncoding == EncodingZRLE
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 || updateRectEncoding == EncodingZRLEE
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 || updateRectEncoding == EncodingTight)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 wereZlibUpdates = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 // If the session is being recorded:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 if (numUpdatesInSession > 1)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 rec.flush(); // Flush the output on each rectangle.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 rec.writeShortBE(updateRectX);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 rec.writeShortBE(updateRectY);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 rec.writeShortBE(updateRectW);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 rec.writeShortBE(updateRectH);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 if (updateRectEncoding == EncodingZlib && !recordFromBeginning) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812 // Here we cannot write Zlib-encoded rectangles because the
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 // decoder won't be able to reproduce zlib stream state.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 if (!zlibWarningShown) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 System.out.println("Warning: Raw encoding will be used "
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
816 + "instead of Zlib in recorded session.");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 zlibWarningShown = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
819 rec.writeIntBE(EncodingRaw);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 rec.writeIntBE(updateRectEncoding);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 if (updateRectEncoding == EncodingTight && !recordFromBeginning
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 && !tightWarningShown) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 System.out.println("Warning: Re-compressing Tight-encoded "
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 + "updates for session recording.");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826 tightWarningShown = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 if (updateRectEncoding < 0 || updateRectEncoding > MaxNormalEncoding)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 return;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834 if (updateRectX + updateRectW > framebufferWidth
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 || updateRectY + updateRectH > framebufferHeight) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 throw new Exception("Framebuffer update rectangle too large: "
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 + updateRectW + "x" + updateRectH + " at (" + updateRectX
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 + "," + updateRectY + ")");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842 // Read CopyRect source X and Y.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 int copyRectSrcX, copyRectSrcY;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
846 void readCopyRect() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 copyRectSrcX = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 copyRectSrcY = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 // If the session is being recorded:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 rec.writeShortBE(copyRectSrcX);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 rec.writeShortBE(copyRectSrcY);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
858 // Read a ServerCutText message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
859 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 String readServerCutText() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862 skipBytes(3);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
863 int len = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
864 byte[] text = new byte[len];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 readFully(text);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 return new String(text);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
868
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
870 // Read an integer in compact representation (1..3 bytes).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 // Such format is used as a part of the Tight encoding.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 // Also, this method records data if session recording is active and
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
873 // the viewer's recordFromBeginning variable is set to true.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
876 int readCompactLen() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877 int[] portion = new int[3];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 portion[0] = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 int byteCount = 1;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880 int len = portion[0] & 0x7F;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
881 if ((portion[0] & 0x80) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 portion[1] = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883 byteCount++;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884 len |= (portion[1] & 0x7F) << 7;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
885 if ((portion[1] & 0x80) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 portion[2] = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
887 byteCount++;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 len |= (portion[2] & 0xFF) << 14;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
889 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
890 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
891
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892 if (rec != null && recordFromBeginning)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
893 for (int i = 0; i < byteCount; i++)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894 rec.writeByte(portion[i]);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
895
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
896 return len;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
897 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
898
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
899 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
900 // Write a FramebufferUpdateRequest message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
901 //
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
902
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
903 void checkDelayData() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 System.out.println("sousinn");
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
905 byte[] b = new byte[1];
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
906 b[0] = (byte) CheckDelay;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
907 os.write(b);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
909
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
910 void writeFramebufferUpdateRequest(int x, int y, int w, int h,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 boolean incremental) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 byte[] b = new byte[10];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
913
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914 b[0] = (byte) FramebufferUpdateRequest;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 b[1] = (byte) (incremental ? 1 : 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 b[2] = (byte) ((x >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 b[3] = (byte) (x & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 b[4] = (byte) ((y >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 b[5] = (byte) (y & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920 b[6] = (byte) ((w >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 b[7] = (byte) (w & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
922 b[8] = (byte) ((h >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 b[9] = (byte) (h & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
924
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
925 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929 // Write a SetPixelFormat message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
930 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
931
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
932 void writeSetPixelFormat(int bitsPerPixel, int depth, boolean bigEndian,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
933 boolean trueColour, int redMax, int greenMax, int blueMax,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934 int redShift, int greenShift, int blueShift) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935 byte[] b = new byte[20];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937 b[0] = (byte) SetPixelFormat;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 b[4] = (byte) bitsPerPixel;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939 b[5] = (byte) depth;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
940 b[6] = (byte) (bigEndian ? 1 : 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941 b[7] = (byte) (trueColour ? 1 : 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942 b[8] = (byte) ((redMax >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
943 b[9] = (byte) (redMax & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
944 b[10] = (byte) ((greenMax >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
945 b[11] = (byte) (greenMax & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
946 b[12] = (byte) ((blueMax >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
947 b[13] = (byte) (blueMax & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 b[14] = (byte) redShift;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 b[15] = (byte) greenShift;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
950 b[16] = (byte) blueShift;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
951
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
952 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956 // Write a FixColourMapEntries message. The values in the red, green and
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 // blue arrays are from 0 to 65535.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 void writeFixColourMapEntries(int firstColour, int nColours, int[] red,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961 int[] green, int[] blue) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962 byte[] b = new byte[6 + nColours * 6];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
963
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
964 b[0] = (byte) FixColourMapEntries;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 b[2] = (byte) ((firstColour >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
966 b[3] = (byte) (firstColour & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
967 b[4] = (byte) ((nColours >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
968 b[5] = (byte) (nColours & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
970 for (int i = 0; i < nColours; i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971 b[6 + i * 6] = (byte) ((red[i] >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 b[6 + i * 6 + 1] = (byte) (red[i] & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
973 b[6 + i * 6 + 2] = (byte) ((green[i] >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 b[6 + i * 6 + 3] = (byte) (green[i] & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
975 b[6 + i * 6 + 4] = (byte) ((blue[i] >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976 b[6 + i * 6 + 5] = (byte) (blue[i] & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
977 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
978
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
980 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
981
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
982 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983 // Write a SetEncodings message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
985
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
986 void writeSetEncodings(int[] encs, int len) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
987 byte[] b = new byte[4 + 4 * len];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 b[0] = (byte) SetEncodings;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990 b[2] = (byte) ((len >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991 b[3] = (byte) (len & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
992
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
993 for (int i = 0; i < len; i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 b[4 + 4 * i] = (byte) ((encs[i] >> 24) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995 b[5 + 4 * i] = (byte) ((encs[i] >> 16) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 b[6 + 4 * i] = (byte) ((encs[i] >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 b[7 + 4 * i] = (byte) (encs[i] & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
999
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 // Write a ClientCutText message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1007 void writeClientCutText(String text) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1008 byte[] b = new byte[8 + text.length()];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1009
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010 b[0] = (byte) ClientCutText;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011 b[4] = (byte) ((text.length() >> 24) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012 b[5] = (byte) ((text.length() >> 16) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013 b[6] = (byte) ((text.length() >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1014 b[7] = (byte) (text.length() & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 System.arraycopy(text.getBytes(), 0, b, 8, text.length());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1018 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1021 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1022 // A buffer for putting pointer and keyboard events before being sent. This
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023 // is to ensure that multiple RFB events generated from a single Java Event
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 // will all be sent in a single network packet. The maximum possible
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025 // length is 4 modifier down events, a single key event followed by 4
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026 // modifier up events i.e. 9 key events or 72 bytes.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029 byte[] eventBuf = new byte[72];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030 int eventBufLen;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1031
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1032 // Useful shortcuts for modifier masks.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1034 final static int CTRL_MASK = InputEvent.CTRL_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 final static int SHIFT_MASK = InputEvent.SHIFT_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 final static int META_MASK = InputEvent.META_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 final static int ALT_MASK = InputEvent.ALT_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 // Write a pointer event message. We may need to send modifier key events
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041 // around it to set the correct modifier state.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1044 int pointerMask = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1045
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1046 void writePointerEvent(MouseEvent evt) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1047 int modifiers = evt.getModifiers();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1048
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049 int mask2 = 2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 int mask3 = 4;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 /*
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1052 * if (viewer.options.reverseMouseButtons2And3) { mask2 = 4; mask3 = 2;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1053 * }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1054 */
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056 // Note: For some reason, AWT does not set BUTTON1_MASK on left
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 // button presses. Here we think that it was the left button if
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 // modifiers do not include BUTTON2_MASK or BUTTON3_MASK.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060 if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 pointerMask = mask2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1063 modifiers &= ~ALT_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064 } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 pointerMask = mask3;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 modifiers &= ~META_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1068 pointerMask = 1;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1069 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070 } else if (evt.getID() == MouseEvent.MOUSE_RELEASED) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1071 pointerMask = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1072 if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073 modifiers &= ~ALT_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074 } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075 modifiers &= ~META_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1077 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1079 eventBufLen = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080 writeModifierKeyEvents(modifiers);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1081
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1082 int x = evt.getX();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083 int y = evt.getY();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085 if (x < 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086 x = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087 if (y < 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088 y = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090 eventBuf[eventBufLen++] = (byte) PointerEvent;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091 eventBuf[eventBufLen++] = (byte) pointerMask;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092 eventBuf[eventBufLen++] = (byte) ((x >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093 eventBuf[eventBufLen++] = (byte) (x & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094 eventBuf[eventBufLen++] = (byte) ((y >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1095 eventBuf[eventBufLen++] = (byte) (y & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1096
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 // Always release all modifiers after an "up" event
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1099 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1101 if (pointerMask == 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102 writeModifierKeyEvents(0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1103 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1104
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 os.write(eventBuf, 0, eventBufLen);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 // Write a key event message. We may need to send modifier key events
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110 // around it to set the correct modifier state. Also we need to translate
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111 // from the Java key values to the X keysym values used by the RFB protocol.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1113
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1114 void writeKeyEvent(KeyEvent evt) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1116 int keyChar = evt.getKeyChar();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1117
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1118 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119 // Ignore event if only modifiers were pressed.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1120 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1121
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1122 // Some JVMs return 0 instead of CHAR_UNDEFINED in getKeyChar().
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1123 if (keyChar == 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1124 keyChar = KeyEvent.CHAR_UNDEFINED;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1125
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1126 if (keyChar == KeyEvent.CHAR_UNDEFINED) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1127 int code = evt.getKeyCode();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1128 if (code == KeyEvent.VK_CONTROL || code == KeyEvent.VK_SHIFT
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1129 || code == KeyEvent.VK_META || code == KeyEvent.VK_ALT)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1130 return;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1131 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1132
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1134 // Key press or key release?
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1136
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1137 boolean down = (evt.getID() == KeyEvent.KEY_PRESSED);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1139 int key;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1140 if (evt.isActionKey()) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1142 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1143 // An action key should be one of the following.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 // If not then just ignore the event.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1145 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1146
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1147 switch (evt.getKeyCode()) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1148 case KeyEvent.VK_HOME:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1149 key = 0xff50;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1150 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1151 case KeyEvent.VK_LEFT:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152 key = 0xff51;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1153 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154 case KeyEvent.VK_UP:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155 key = 0xff52;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1156 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 case KeyEvent.VK_RIGHT:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 key = 0xff53;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 case KeyEvent.VK_DOWN:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 key = 0xff54;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 case KeyEvent.VK_PAGE_UP:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 key = 0xff55;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166 case KeyEvent.VK_PAGE_DOWN:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 key = 0xff56;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169 case KeyEvent.VK_END:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 key = 0xff57;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 case KeyEvent.VK_INSERT:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173 key = 0xff63;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 case KeyEvent.VK_F1:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176 key = 0xffbe;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178 case KeyEvent.VK_F2:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179 key = 0xffbf;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 case KeyEvent.VK_F3:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182 key = 0xffc0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1183 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184 case KeyEvent.VK_F4:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1185 key = 0xffc1;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187 case KeyEvent.VK_F5:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 key = 0xffc2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 case KeyEvent.VK_F6:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191 key = 0xffc3;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 case KeyEvent.VK_F7:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194 key = 0xffc4;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 case KeyEvent.VK_F8:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 key = 0xffc5;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 case KeyEvent.VK_F9:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200 key = 0xffc6;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202 case KeyEvent.VK_F10:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203 key = 0xffc7;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205 case KeyEvent.VK_F11:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 key = 0xffc8;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208 case KeyEvent.VK_F12:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 key = 0xffc9;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 default:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 return;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1214
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1215 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1217 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1218 // A "normal" key press. Ordinary ASCII characters go straight
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219 // through.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220 // For CTRL-<letter>, CTRL is sent separately so just send <letter>.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1221 // Backspace, tab, return, escape and delete have special keysyms.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1222 // Anything else we ignore.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1223 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1224
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 key = keyChar;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227 if (key < 0x20) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228 if (evt.isControlDown()) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1229 key += 0x60;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1230 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1231 switch (key) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1232 case KeyEvent.VK_BACK_SPACE:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233 key = 0xff08;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1234 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1235 case KeyEvent.VK_TAB:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1236 key = 0xff09;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1237 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238 case KeyEvent.VK_ENTER:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239 key = 0xff0d;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1240 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1241 case KeyEvent.VK_ESCAPE:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1242 key = 0xff1b;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1243 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1244 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1246 } else if (key == 0x7f) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1247 // Delete
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1248 key = 0xffff;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1249 } else if (key > 0xff) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1250 // JDK1.1 on X incorrectly passes some keysyms straight through,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1251 // so we do too. JDK1.1.4 seems to have fixed this.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1252 // The keysyms passed are 0xff00 .. XK_BackSpace .. XK_Delete
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253 // Also, we pass through foreign currency keysyms
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1254 // (0x20a0..0x20af).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1255 if ((key < 0xff00 || key > 0xffff)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1256 && !(key >= 0x20a0 && key <= 0x20af))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1257 return;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1258 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1259 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1260
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1261 // Fake keyPresses for keys that only generates keyRelease events
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262 if ((key == 0xe5) || (key == 0xc5) || // XK_aring / XK_Aring
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1263 (key == 0xe4) || (key == 0xc4) || // XK_adiaeresis /
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 // XK_Adiaeresis
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265 (key == 0xf6) || (key == 0xd6) || // XK_odiaeresis /
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266 // XK_Odiaeresis
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267 (key == 0xa7) || (key == 0xbd) || // XK_section / XK_onehalf
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1268 (key == 0xa3)) { // XK_sterling
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1269 // Make sure we do not send keypress events twice on platforms
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 // with correct JVMs (those that actually report KeyPress for all
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1271 // keys)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1272 if (down)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273 brokenKeyPressed = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1275 if (!down && !brokenKeyPressed) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1276 // We've got a release event for this key, but haven't received
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1277 // a press. Fake it.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1278 eventBufLen = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1279 writeModifierKeyEvents(evt.getModifiers());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1280 writeKeyEvent(key, true);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1281 os.write(eventBuf, 0, eventBufLen);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284 if (!down)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1285 brokenKeyPressed = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 eventBufLen = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 writeModifierKeyEvents(evt.getModifiers());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 writeKeyEvent(key, down);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1291
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1292 // Always release all modifiers after an "up" event
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293 if (!down)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1294 writeModifierKeyEvents(0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1295
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1296 os.write(eventBuf, 0, eventBufLen);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1297 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1298
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1299 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1300 // Add a raw key event with the given X keysym to eventBuf.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1301 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1302
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303 void writeKeyEvent(int keysym, boolean down) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304 eventBuf[eventBufLen++] = (byte) KeyboardEvent;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1305 eventBuf[eventBufLen++] = (byte) (down ? 1 : 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 eventBuf[eventBufLen++] = (byte) 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307 eventBuf[eventBufLen++] = (byte) 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308 eventBuf[eventBufLen++] = (byte) ((keysym >> 24) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1309 eventBuf[eventBufLen++] = (byte) ((keysym >> 16) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310 eventBuf[eventBufLen++] = (byte) ((keysym >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311 eventBuf[eventBufLen++] = (byte) (keysym & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1312 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1315 // Write key events to set the correct modifier state.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1316 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1317
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1318 int oldModifiers = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1319
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1320 void writeModifierKeyEvents(int newModifiers) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1321 if ((newModifiers & CTRL_MASK) != (oldModifiers & CTRL_MASK))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1322 writeKeyEvent(0xffe3, (newModifiers & CTRL_MASK) != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1323
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1324 if ((newModifiers & SHIFT_MASK) != (oldModifiers & SHIFT_MASK))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1325 writeKeyEvent(0xffe1, (newModifiers & SHIFT_MASK) != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 if ((newModifiers & META_MASK) != (oldModifiers & META_MASK))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 writeKeyEvent(0xffe7, (newModifiers & META_MASK) != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330 if ((newModifiers & ALT_MASK) != (oldModifiers & ALT_MASK))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1331 writeKeyEvent(0xffe9, (newModifiers & ALT_MASK) != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1332
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1333 oldModifiers = newModifiers;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1334 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1335
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1336 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1337 // Compress and write the data into the recorded session file. This
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1338 // method assumes the recording is on (rec != null).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1339 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1340
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 void recordCompressedData(byte[] data, int off, int len) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1342 Deflater deflater = new Deflater();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1343 deflater.setInput(data, off, len);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1344 int bufSize = len + len / 100 + 12;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1345 byte[] buf = new byte[bufSize];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1346 deflater.finish();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1347 int compressedSize = deflater.deflate(buf);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1348 recordCompactLen(compressedSize);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1349 rec.write(buf, 0, compressedSize);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1350 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1351
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1352 void recordCompressedData(byte[] data) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1353 recordCompressedData(data, 0, data.length);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1354 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1355
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1356 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1357 // Write an integer in compact representation (1..3 bytes) into the
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1358 // recorded session file. This method assumes the recording is on
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359 // (rec != null).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1360 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 void recordCompactLen(int len) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363 byte[] buf = new byte[3];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1364 int bytes = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365 buf[bytes++] = (byte) (len & 0x7F);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1366 if (len > 0x7F) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1367 buf[bytes - 1] |= 0x80;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1368 buf[bytes++] = (byte) (len >> 7 & 0x7F);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1369 if (len > 0x3FFF) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1370 buf[bytes - 1] |= 0x80;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1371 buf[bytes++] = (byte) (len >> 14 & 0xFF);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1372 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1373 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1374 rec.write(buf, 0, bytes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1375 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1376
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1377 public void startTiming() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1378 timing = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1379
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1380 // Carry over up to 1s worth of previous rate for smoothing.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1381
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1382 if (timeWaitedIn100us > 10000) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1383 timedKbits = timedKbits * 10000 / timeWaitedIn100us;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1384 timeWaitedIn100us = 10000;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1385 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1386 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1387
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1388 public void stopTiming() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1389 timing = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1390 if (timeWaitedIn100us < timedKbits / 2)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1391 timeWaitedIn100us = timedKbits / 2; // upper limit 20Mbit/s
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1392 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1393
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1394 public long kbitsPerSecond() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1395 return timedKbits * 10000 / timeWaitedIn100us;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1396 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1397
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1398 public long timeWaited() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1399 return timeWaitedIn100us;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1400 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1401
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1402 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1403 // Methods for reading data via our DataInputStream member variable (is).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1404 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1405 // In addition to reading data, the readFully() methods updates variables
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1406 // used to estimate data throughput.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1407 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1408
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1409 public void readFully(byte b[]) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1410 readFully(b, 0, b.length);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1411 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1412
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1413 long before = System.currentTimeMillis();
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1414
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1415 public void readFully(byte b[], int off, int len) throws IOException {
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1416 // long before = 0;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1417 if (timing)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1418 before = System.currentTimeMillis();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1420 is.readFully(b, off, len);
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1421
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1422 /*
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1423 * if(b.length==16) { b[4] = (byte)0; b[5] = (byte)0; b[6] = (byte)0;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1424 * b[7] = (byte)0; System.out.println("----------------------"); }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1425 */
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1426 // System.out.println("Blength:"+b.length);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1427 // for(int i=0 ; i<=b.length ; i++) {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1428 // if(i>b.length/2)
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1429 // b[i] = 10;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1430 // }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1431
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1432 /*
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1433 * if (timing) { long after = System.currentTimeMillis(); long
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1434 * newTimeWaited = (after - before) * 10; int newKbits = len * 8 / 1000;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1435 *
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1436 * // limit rate to between 10kbit/s and 40Mbit/s
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1437 *
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1438 * if (newTimeWaited > newKbits * 1000) newTimeWaited = newKbits * 1000;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1439 * if (newTimeWaited < newKbits / 4) newTimeWaited = newKbits / 4;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1440 *
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1441 * timeWaitedIn100us += newTimeWaited; timedKbits += newKbits; before =
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1442 * after; }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1443 */
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1444 numBytesRead += len;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1445 // System.out.println("numBytesRead:"+numBytesRead);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1446 }
4
657c691c2936 add readhandler.java
one
parents: 3
diff changeset
1447
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1448 final int available() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1449 return is.available();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1450 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1451
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1452 // FIXME: DataInputStream::skipBytes() is not guaranteed to skip
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1453 // exactly n bytes. Probably we don't want to use this method.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1454 final int skipBytes(int n) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1455 int r = is.skipBytes(n);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1456 numBytesRead += r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1457 return r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1458 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1459
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1460 final int readU8() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1461 int r = is.readUnsignedByte();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1462 numBytesRead++;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1463
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1464 return r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1465 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1466
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1467 final int readU16() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1468 int r = is.readUnsignedShort();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1469 numBytesRead += 2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1470 return r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1471 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1472
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1473 final int readU32() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1474 int r = is.readInt();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1475 numBytesRead += 4;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1476 return r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1477 }
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1478
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1479 public LinkedList<ByteBuffer> blockingUpdateRectangle(
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1480 LinkedList<ByteBuffer> input, int w, int h) {
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1481
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1482 return null;
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1483 }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1484 }