annotate src/treeVnc/RfbProto.java @ 3:3b341997141a

broadcast socket trying
author one
date Mon, 23 Apr 2012 20:18:23 +0900
parents 5d72f4c7371d
children 657c691c2936
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.*;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
31 import java.net.InetSocketAddress;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 import java.net.Socket;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
33 import java.net.SocketException;
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
34 import java.nio.ByteBuffer;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
35 import java.nio.channels.ServerSocketChannel;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
36 import java.nio.channels.spi.AbstractSelector;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
37 import java.nio.channels.spi.SelectorProvider;
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
38 import java.util.LinkedList;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 import java.util.zip.*;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
41 public class RfbProto {
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 final static String versionMsg_3_3 = "RFB 003.003\n",
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
44 versionMsg_3_7 = "RFB 003.007\n", versionMsg_3_8 = "RFB 003.008\n",
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
45 versionMsg_3_855 = "RFB 003.855\n";
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 // Vendor signatures: standard VNC/RealVNC, TridiaVNC, and TightVNC
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 final static String StandardVendor = "STDV", TridiaVncVendor = "TRDV",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 TightVncVendor = "TGHT";
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 // Security types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 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
53 SecTypeTight = 16;
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 // Supported tunneling types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 final static int NoTunneling = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 final static String SigNoTunneling = "NOTUNNEL";
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 authentication types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 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
61 final static String SigAuthNone = "NOAUTH__", SigAuthVNC = "VNCAUTH_",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 SigAuthUnixLogin = "ULGNAUTH";
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 // VNC authentication results
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 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
66
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 // Standard server-to-client messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 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
69 ServerCutText = 3;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
70
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 // Check Delay Top form Bottom
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 final static int CheckDelay = 11;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 // Non-standard server-to-client messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 final static int EndOfContinuousUpdates = 150;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 final static String SigEndOfContinuousUpdates = "CUS_EOCU";
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 // Standard client-to-server messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 final static int SetPixelFormat = 0, FixColourMapEntries = 1,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 SetEncodings = 2, FramebufferUpdateRequest = 3, KeyboardEvent = 4,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 PointerEvent = 5, ClientCutText = 6;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 // Non-standard client-to-server messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 final static int EnableContinuousUpdates = 150;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 final static String SigEnableContinuousUpdates = "CUC_ENCU";
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 // Supported encodings and pseudo-encodings
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 final static int EncodingRaw = 0, EncodingCopyRect = 1, EncodingRRE = 2,
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
89 EncodingCoRRE = 4, EncodingHextile = 5, EncodingZlib = 6,
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 EncodingTight = 7, EncodingZRLEE = 15, EncodingZRLE = 16,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 EncodingCompressLevel0 = 0xFFFFFF00,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 EncodingQualityLevel0 = 0xFFFFFFE0, EncodingXCursor = 0xFFFFFF10,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 EncodingRichCursor = 0xFFFFFF11, EncodingPointerPos = 0xFFFFFF18,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 EncodingLastRect = 0xFFFFFF20, EncodingNewFBSize = 0xFFFFFF21;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 final static String SigEncodingRaw = "RAW_____",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 SigEncodingCopyRect = "COPYRECT", SigEncodingRRE = "RRE_____",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 SigEncodingCoRRE = "CORRE___", SigEncodingHextile = "HEXTILE_",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 SigEncodingZlib = "ZLIB____", SigEncodingTight = "TIGHT___",
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
99 SigEncodingZRLEE = "ZRLEE___", SigEncodingZRLE = "ZRLE____",
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 SigEncodingCompressLevel0 = "COMPRLVL",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 SigEncodingQualityLevel0 = "JPEGQLVL",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 SigEncodingXCursor = "X11CURSR",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 SigEncodingRichCursor = "RCHCURSR",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 SigEncodingPointerPos = "POINTPOS",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 SigEncodingLastRect = "LASTRECT",
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 SigEncodingNewFBSize = "NEWFBSIZ";
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 final static int MaxNormalEncoding = 255;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 // Contstants used in the Hextile decoder
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 final static int HextileRaw = 1, HextileBackgroundSpecified = 2,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 HextileForegroundSpecified = 4, HextileAnySubrects = 8,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 HextileSubrectsColoured = 16;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 // Contstants used in the Tight decoder
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 final static int TightMinToCompress = 12;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 final static int TightExplicitFilter = 0x04, TightFill = 0x08,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 TightJpeg = 0x09, TightMaxSubencoding = 0x09,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 TightFilterCopy = 0x00, TightFilterPalette = 0x01,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 TightFilterGradient = 0x02;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
122 static AbstractSelector selector;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 String host;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 int port;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 Socket sock;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 OutputStream os;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 SessionRecorder rec;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 boolean inNormalProtocol = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 VncViewer viewer;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 MyVncClient myVncClient;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 // 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
133 // 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
134 // count how many bytes were read.
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
135 // private DataInputStream is;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 protected DataInputStream is;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
137 // private long numBytesRead = 0;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 protected long numBytesRead = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 public long getNumBytesRead() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 return numBytesRead;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 }
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 // 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
145 // 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
146 // 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
147 // 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
148 boolean brokenKeyPressed = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 // 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
151 // containing Zlib-, ZRLE- or Tight-encoded data.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 boolean wereZlibUpdates = 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 false if the startSession() was called after
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 // 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
156 // framebuffer update.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 boolean recordFromBeginning = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 // 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
160 // sessions only once per each saved session file.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 boolean zlibWarningShown;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 boolean tightWarningShown;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 // 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
165 // 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
166 // 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
167 // 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
168 // 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
169 // playback.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 int numUpdatesInSession;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 // Measuring network throughput.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 boolean timing;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 long timeWaitedIn100us;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 long timedKbits;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 // Protocol version and TightVNC-specific protocol options.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 int serverMajor, serverMinor;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 int clientMajor, clientMinor;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 boolean protocolTightVNC;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 CapsContainer tunnelCaps, authCaps;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 CapsContainer serverMsgCaps, clientMsgCaps;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 CapsContainer encodingCaps;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 // If true, informs that the RFB socket was closed.
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
186 // private boolean closed;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 protected boolean closed;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
188
1
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
189 private byte[] broadCastBuf = new byte[64000];
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 // Constructor. Make TCP connection to RFB server.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 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
195 viewer = v;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 host = h;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 port = p;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 if (viewer.socketFactory == null) {
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
200 sock = newSocket(host, port);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 try {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 Class factoryClass = Class.forName(viewer.socketFactory);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 SocketFactory factory = (SocketFactory) factoryClass
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 .newInstance();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 if (viewer.inAnApplet)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 sock = factory.createSocket(host, port, viewer);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 else
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 sock = factory.createSocket(host, port, viewer.mainArgs);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 } catch (Exception e) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 e.printStackTrace();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 throw new IOException(e.getMessage());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 16384));
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 os = sock.getOutputStream();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 timing = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 timeWaitedIn100us = 5;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 timedKbits = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 }
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
223
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 RfbProto(String h, int p) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 host = h;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 port = p;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
228 sock = newSocket(host, port);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 16384));
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 os = sock.getOutputStream();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 timing = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 timeWaitedIn100us = 5;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 timedKbits = 0;
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
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
239 private ServerSocket newSocket(String host, int port) {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
240 ServerSocketChannel ssChannel = SelectorProvider.provider().openServerSocketChannel();
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
241 ssChannel.socket().setReuseAddress(true);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
242 // this should work for IPv6/IPv4 dual stack
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
243 // check this using netstat -an result tcp46.
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
244 try {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
245 InetSocketAddress address = new InetSocketAddress(host, port);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
246 ssChannel.socket().bind(address);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
247 } catch (SocketException e) {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
248 // for some bad IPv6 implementation
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
249 ssChannel.socket().bind(new InetSocketAddress(port));
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
250 }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
251 ssChannel.configureBlocking(false);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
252 return ssChannel.socket();
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
253 }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
255 public RfbProto() {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
256
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
257 }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
258
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
259 public void initOnce() throws IOException {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
260 selector = SelectorProvider.provider().openSelector();
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
261 }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
262
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
263 public void changeRfbProto(String h, int port) throws IOException {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
264 host = h;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
265 sock = null;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
266 sock = newSocket(host, port);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
267 is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
268 16384));
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
269 os = sock.getOutputStream();
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
270
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
271 timing = false;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
272 timeWaitedIn100us = 5;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
273 timedKbits = 0;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
274 }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 synchronized void close() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 try {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 sock.close();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 closed = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 System.out.println("RFB socket closed");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 rec.close();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 rec = null;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 } catch (Exception e) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 e.printStackTrace();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 synchronized boolean closed() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 return closed;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 // Read server's protocol version message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 //
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 void readVersionMsg() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 byte[] b = new byte[12];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 readFully(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 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
305 || (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
306 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 || (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
308 || (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
309 throw new Exception("Host " + host + " port " + port
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 + " is not an RFB server");
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 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
314 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
315
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 if (serverMajor < 3) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 throw new Exception(
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 "RFB server does not support protocol version 3");
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 }
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 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 // Write our protocol version message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 //
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 void writeVersionMsg() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 clientMajor = 3;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 if (serverMajor > 3 || serverMinor >= 8) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 clientMinor = 8;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 os.write(versionMsg_3_8.getBytes());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 } else if (serverMinor >= 7) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 clientMinor = 7;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 os.write(versionMsg_3_7.getBytes());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 clientMinor = 3;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 os.write(versionMsg_3_3.getBytes());
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 protocolTightVNC = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 initCapabilities();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 }
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
341
0
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 // Negotiate the authentication scheme.
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 int negotiateSecurity() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 return (clientMinor >= 7) ? selectSecurityType() : readSecurityType();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 // 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
352 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 int readSecurityType() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 int secType = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 switch (secType) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 case SecTypeInvalid:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 readConnFailedReason();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 return SecTypeInvalid; // should never be executed
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 case SecTypeNone:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 case SecTypeVncAuth:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 return secType;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 default:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 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
366 + secType);
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 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369
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 // 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
372 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 int selectSecurityType() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 int secType = SecTypeInvalid;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 // Read the list of secutiry types.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 int nSecTypes = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 if (nSecTypes == 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 readConnFailedReason();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 return SecTypeInvalid; // should never be executed
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 byte[] secTypes = new byte[nSecTypes];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 readFully(secTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 // 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
387 for (int i = 0; i < nSecTypes; i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 if (secTypes[i] == SecTypeTight) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 protocolTightVNC = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 os.write(SecTypeTight);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 return SecTypeTight;
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 }
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 // Find first supported security type.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 for (int i = 0; i < nSecTypes; i++) {
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
397 // if (secTypes[i] == SecTypeNone || secTypes[i] == SecTypeVncAuth)
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
398 // {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
399 if (secTypes[i] == SecTypeNone || secTypes[i] == SecTypeVncAuth
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
400 || secTypes[i] == MyRfbProtoProxy.SecTypeReqAccess) {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
401 secType = secTypes[i];
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 }
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
404 }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 if (secType == SecTypeInvalid) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 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
408 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 os.write(secType);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 return secType;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 }
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 // Perform "no authentication".
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 void authenticateNone() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 if (clientMinor >= 8)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 readSecurityResult("No authentication");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 // Perform standard VNC Authentication.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 //
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 void authenticateVNC(String pw) throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 byte[] challenge = new byte[16];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 readFully(challenge);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 if (pw.length() > 8)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 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
434
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 // Truncate password on the first zero byte.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 int firstZero = pw.indexOf(0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 if (firstZero != -1)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 pw = pw.substring(0, firstZero);
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 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
441 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
442
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 DesCipher des = new DesCipher(key);
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 des.encrypt(challenge, 0, challenge, 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 des.encrypt(challenge, 8, challenge, 8);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 os.write(challenge);
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 readSecurityResult("VNC authentication");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452
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 // Read security result.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 // Throws an exception on authentication failure.
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 void readSecurityResult(String authType) throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 int securityResult = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 switch (securityResult) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 case VncAuthOK:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 System.out.println(authType + ": success");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 case VncAuthFailed:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 if (clientMinor >= 8)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 readConnFailedReason();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 throw new Exception(authType + ": failed");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 case VncAuthTooMany:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 throw new Exception(authType + ": failed, too many tries");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 default:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 throw new Exception(authType + ": unknown result " + securityResult);
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 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 // 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
478 // and throw an exception.
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 void readConnFailedReason() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 int reasonLen = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 byte[] reason = new byte[reasonLen];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 readFully(reason);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 throw new Exception(new String(reason));
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 // Initialize capability lists (TightVNC protocol extensions).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 void initCapabilities() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 tunnelCaps = new CapsContainer();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 authCaps = new CapsContainer();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 serverMsgCaps = new CapsContainer();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 clientMsgCaps = new CapsContainer();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 encodingCaps = new CapsContainer();
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 // Supported authentication methods
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 authCaps.add(AuthNone, StandardVendor, SigAuthNone, "No authentication");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 authCaps.add(AuthVNC, StandardVendor, SigAuthVNC,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 "Standard VNC password authentication");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 // Supported non-standard server-to-client messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 // [NONE]
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 // Supported non-standard client-to-server messages
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 // [NONE]
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 // Supported encoding types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 encodingCaps.add(EncodingCopyRect, StandardVendor, SigEncodingCopyRect,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 "Standard CopyRect encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 encodingCaps.add(EncodingRRE, StandardVendor, SigEncodingRRE,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 "Standard RRE encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 encodingCaps.add(EncodingCoRRE, StandardVendor, SigEncodingCoRRE,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 "Standard CoRRE encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 encodingCaps.add(EncodingHextile, StandardVendor, SigEncodingHextile,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 "Standard Hextile encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 encodingCaps.add(EncodingZRLE, StandardVendor, SigEncodingZRLE,
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
520 "Standard ZRLE encoding");
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 encodingCaps.add(EncodingZRLEE, StandardVendor, SigEncodingZRLEE,
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
522 "Standard ZRLE(E) encoding");
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 encodingCaps.add(EncodingZlib, TridiaVncVendor, SigEncodingZlib,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 "Zlib encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 encodingCaps.add(EncodingTight, TightVncVendor, SigEncodingTight,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 "Tight encoding");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 // Supported pseudo-encoding types
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 encodingCaps.add(EncodingCompressLevel0, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 SigEncodingCompressLevel0, "Compression level");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 encodingCaps.add(EncodingQualityLevel0, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 SigEncodingQualityLevel0, "JPEG quality level");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 encodingCaps.add(EncodingXCursor, TightVncVendor, SigEncodingXCursor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 "X-style cursor shape update");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 encodingCaps.add(EncodingRichCursor, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 SigEncodingRichCursor, "Rich-color cursor shape update");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 encodingCaps.add(EncodingPointerPos, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 SigEncodingPointerPos, "Pointer position update");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 encodingCaps.add(EncodingLastRect, TightVncVendor, SigEncodingLastRect,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 "LastRect protocol extension");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 encodingCaps.add(EncodingNewFBSize, TightVncVendor,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 SigEncodingNewFBSize, "Framebuffer size change");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 // Setup tunneling (TightVNC protocol extensions)
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 void setupTunneling() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 int nTunnelTypes = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 if (nTunnelTypes != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 readCapabilityList(tunnelCaps, nTunnelTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 // We don't support tunneling yet.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 writeInt(NoTunneling);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 // Negotiate authentication scheme (TightVNC protocol extensions)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 int negotiateAuthenticationTight() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
566 int nAuthTypes = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 if (nAuthTypes == 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 return AuthNone;
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 readCapabilityList(authCaps, nAuthTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 for (int i = 0; i < authCaps.numEnabled(); i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 int authType = authCaps.getByOrder(i);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 if (authType == AuthNone || authType == AuthVNC) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 writeInt(authType);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 return authType;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 }
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 throw new Exception("No suitable authentication scheme found");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 }
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 // Read a capability list (TightVNC protocol extensions)
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 void readCapabilityList(CapsContainer caps, int count) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 int code;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 byte[] vendor = new byte[4];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 byte[] name = new byte[8];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 for (int i = 0; i < count; i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 code = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 readFully(vendor);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 readFully(name);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 caps.enable(new CapabilityInfo(code, vendor, name));
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 // 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
599 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 void writeInt(int value) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 byte[] b = new byte[4];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 b[0] = (byte) ((value >> 24) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 b[1] = (byte) ((value >> 16) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 b[2] = (byte) ((value >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 b[3] = (byte) (value & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 // Write the client initialisation message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 void writeClientInit() throws IOException {
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
615 /*
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
616 * if (viewer.options.shareDesktop) {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
617 */
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
618
0
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 * shared flag
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 */
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
622 os.write(1);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
623 // os.write(0);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
625 // viewer.options.disableShareDesktop();
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 // Read the server initialisation message
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 String desktopName;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 int framebufferWidth, framebufferHeight;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 int bitsPerPixel, depth;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 boolean bigEndian, trueColour;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 int redMax, greenMax, blueMax, redShift, greenShift, blueShift;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 void readServerInit() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 framebufferWidth = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 framebufferHeight = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 bitsPerPixel = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 depth = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 bigEndian = (readU8() != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 trueColour = (readU8() != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 redMax = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 greenMax = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 blueMax = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 redShift = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 greenShift = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 blueShift = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 byte[] pad = new byte[3];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 readFully(pad);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 int nameLength = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 byte[] name = new byte[nameLength];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 readFully(name);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 desktopName = new String(name);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
659 // Read interaction capabilities (TightVNC protocol extensions)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 if (protocolTightVNC) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 int nServerMessageTypes = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 int nClientMessageTypes = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 int nEncodingTypes = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 readCapabilityList(serverMsgCaps, nServerMessageTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 readCapabilityList(clientMsgCaps, nClientMessageTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 readCapabilityList(encodingCaps, nEncodingTypes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 inNormalProtocol = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 // 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
675 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 void startSession(String fname) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 rec = new SessionRecorder(fname);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 rec.writeHeader();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 rec.write(versionMsg_3_3.getBytes());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 rec.writeIntBE(SecTypeNone);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 rec.writeShortBE(framebufferWidth);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 rec.writeShortBE(framebufferHeight);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 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
685 (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
686 rec.write(fbsServerInitMsg);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
687 rec.writeIntBE(desktopName.length());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 rec.write(desktopName.getBytes());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 numUpdatesInSession = 0;
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 // 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
692 // 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
693 // 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
694 // Tight, instead of one ``wereZlibUpdates'' variable.
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 if (wereZlibUpdates)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 recordFromBeginning = false;
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 zlibWarningShown = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 tightWarningShown = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 // Close session file.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 void closeSession() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 rec.close();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 rec = null;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 }
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
715 // Set new framebuffer size
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 //
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 void setFramebufferSize(int width, int height) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 framebufferWidth = width;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 framebufferHeight = height;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722
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 // Read the server message type
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 int readServerMessageType() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 int msgType = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 // If the session is being recorded:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 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
733 rec.writeByte(msgType);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 if (numUpdatesInSession > 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 rec.flush();
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 }
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 return msgType;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 // Read a FramebufferUpdate message
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 int updateNRects;
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 void readFramebufferUpdate() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 skipBytes(1);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 updateNRects = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 // System.out.println(updateNRects);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 // If the session is being recorded:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 rec.writeByte(FramebufferUpdate);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 rec.writeByte(0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 rec.writeShortBE(updateNRects);
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 numUpdatesInSession++;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 }
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 // Read a FramebufferUpdate rectangle header
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 int updateRectX, updateRectY, updateRectW, updateRectH, updateRectEncoding;
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 void readFramebufferUpdateRectHdr() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 updateRectX = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 updateRectY = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 updateRectW = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 updateRectH = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 updateRectEncoding = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 // System.out.println("readU16&32");
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 (updateRectEncoding == EncodingZlib
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 || updateRectEncoding == EncodingZRLE
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 || updateRectEncoding == EncodingZRLEE
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 || updateRectEncoding == EncodingTight)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 wereZlibUpdates = true;
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 // If the session is being recorded:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 if (numUpdatesInSession > 1)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 rec.flush(); // Flush the output on each rectangle.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 rec.writeShortBE(updateRectX);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 rec.writeShortBE(updateRectY);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 rec.writeShortBE(updateRectW);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 rec.writeShortBE(updateRectH);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 if (updateRectEncoding == EncodingZlib && !recordFromBeginning) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 // 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
791 // 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
792 if (!zlibWarningShown) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 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
794 + "instead of Zlib in recorded session.");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 zlibWarningShown = true;
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 rec.writeIntBE(EncodingRaw);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 rec.writeIntBE(updateRectEncoding);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 if (updateRectEncoding == EncodingTight && !recordFromBeginning
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 && !tightWarningShown) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802 System.out.println("Warning: Re-compressing Tight-encoded "
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 + "updates for session recording.");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 tightWarningShown = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 if (updateRectEncoding < 0 || updateRectEncoding > MaxNormalEncoding)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 return;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812 if (updateRectX + updateRectW > framebufferWidth
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 || updateRectY + updateRectH > framebufferHeight) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 throw new Exception("Framebuffer update rectangle too large: "
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 + updateRectW + "x" + updateRectH + " at (" + updateRectX
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
816 + "," + updateRectY + ")");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 }
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 // Read CopyRect source X and Y.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 int copyRectSrcX, copyRectSrcY;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 void readCopyRect() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 copyRectSrcX = readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826 copyRectSrcY = readU16();
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 // If the session is being recorded:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829 if (rec != null) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 rec.writeShortBE(copyRectSrcX);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 rec.writeShortBE(copyRectSrcY);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 }
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 // Read a ServerCutText message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 String readServerCutText() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 skipBytes(3);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 int len = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842 byte[] text = new byte[len];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843 readFully(text);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 return new String(text);
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 // 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
849 // 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
850 // 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
851 // 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
852 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 int readCompactLen() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 int[] portion = new int[3];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856 portion[0] = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 int byteCount = 1;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
858 int len = portion[0] & 0x7F;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
859 if ((portion[0] & 0x80) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 portion[1] = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 byteCount++;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862 len |= (portion[1] & 0x7F) << 7;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
863 if ((portion[1] & 0x80) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
864 portion[2] = readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 byteCount++;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 len |= (portion[2] & 0xFF) << 14;
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 if (rec != null && recordFromBeginning)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 for (int i = 0; i < byteCount; i++)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 rec.writeByte(portion[i]);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
873
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 return len;
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 // Write a FramebufferUpdateRequest message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 //
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
880
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
881 void checkDelayData() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 System.out.println("sousinn");
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
883 byte[] b = new byte[1];
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
884 b[0] = (byte) CheckDelay;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
885 os.write(b);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
887
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 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
889 boolean incremental) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
890 byte[] b = new byte[10];
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 b[0] = (byte) FramebufferUpdateRequest;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
893 b[1] = (byte) (incremental ? 1 : 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894 b[2] = (byte) ((x >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
895 b[3] = (byte) (x & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
896 b[4] = (byte) ((y >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
897 b[5] = (byte) (y & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
898 b[6] = (byte) ((w >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
899 b[7] = (byte) (w & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
900 b[8] = (byte) ((h >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
901 b[9] = (byte) (h & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
902
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
903 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
905
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
906 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907 // Write a SetPixelFormat message
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 writeSetPixelFormat(int bitsPerPixel, int depth, boolean bigEndian,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 boolean trueColour, int redMax, int greenMax, int blueMax,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 int redShift, int greenShift, int blueShift) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
913 byte[] b = new byte[20];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 b[0] = (byte) SetPixelFormat;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 b[4] = (byte) bitsPerPixel;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 b[5] = (byte) depth;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 b[6] = (byte) (bigEndian ? 1 : 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 b[7] = (byte) (trueColour ? 1 : 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920 b[8] = (byte) ((redMax >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 b[9] = (byte) (redMax & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
922 b[10] = (byte) ((greenMax >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 b[11] = (byte) (greenMax & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
924 b[12] = (byte) ((blueMax >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
925 b[13] = (byte) (blueMax & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926 b[14] = (byte) redShift;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927 b[15] = (byte) greenShift;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 b[16] = (byte) blueShift;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
930 os.write(b);
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
933 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934 // 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
935 // blue arrays are from 0 to 65535.
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 void writeFixColourMapEntries(int firstColour, int nColours, int[] red,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939 int[] green, int[] blue) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
940 byte[] b = new byte[6 + nColours * 6];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942 b[0] = (byte) FixColourMapEntries;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
943 b[2] = (byte) ((firstColour >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
944 b[3] = (byte) (firstColour & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
945 b[4] = (byte) ((nColours >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
946 b[5] = (byte) (nColours & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
947
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 for (int i = 0; i < nColours; i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 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
950 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
951 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
952 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
953 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
954 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
955 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 os.write(b);
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 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961 // Write a SetEncodings message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962 //
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 void writeSetEncodings(int[] encs, int len) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 byte[] b = new byte[4 + 4 * len];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
966
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
967 b[0] = (byte) SetEncodings;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
968 b[2] = (byte) ((len >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969 b[3] = (byte) (len & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
970
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971 for (int i = 0; i < len; i++) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 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
973 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
974 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
975 b[7 + 4 * i] = (byte) (encs[i] & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976 }
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 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979 }
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 // Write a ClientCutText message
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983 //
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 void writeClientCutText(String text) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
986 byte[] b = new byte[8 + text.length()];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
987
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988 b[0] = (byte) ClientCutText;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 b[4] = (byte) ((text.length() >> 24) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990 b[5] = (byte) ((text.length() >> 16) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991 b[6] = (byte) ((text.length() >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
992 b[7] = (byte) (text.length() & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
993
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 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
995
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 os.write(b);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 }
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 // 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
1001 // 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
1002 // 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
1003 // 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
1004 // 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
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 byte[] eventBuf = new byte[72];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1008 int eventBufLen;
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 // Useful shortcuts for modifier masks.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012 final static int CTRL_MASK = InputEvent.CTRL_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013 final static int SHIFT_MASK = InputEvent.SHIFT_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1014 final static int META_MASK = InputEvent.META_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015 final static int ALT_MASK = InputEvent.ALT_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016
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 // 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
1019 // around it to set the correct modifier state.
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 int pointerMask = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 void writePointerEvent(MouseEvent evt) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025 int modifiers = evt.getModifiers();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 int mask2 = 2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028 int mask3 = 4;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029 /*
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1030 * if (viewer.options.reverseMouseButtons2And3) { mask2 = 4; mask3 = 2;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1031 * }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1032 */
0
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 // 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
1035 // 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
1036 // 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
1037
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038 if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 pointerMask = mask2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041 modifiers &= ~ALT_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042 } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043 pointerMask = mask3;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1044 modifiers &= ~META_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1045 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1046 pointerMask = 1;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1047 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1048 } else if (evt.getID() == MouseEvent.MOUSE_RELEASED) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049 pointerMask = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 modifiers &= ~ALT_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 modifiers &= ~META_MASK;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 }
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 eventBufLen = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 writeModifierKeyEvents(modifiers);
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 int x = evt.getX();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 int y = evt.getY();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1063 if (x < 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064 x = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 if (y < 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 y = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1068 eventBuf[eventBufLen++] = (byte) PointerEvent;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1069 eventBuf[eventBufLen++] = (byte) pointerMask;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070 eventBuf[eventBufLen++] = (byte) ((x >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1071 eventBuf[eventBufLen++] = (byte) (x & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1072 eventBuf[eventBufLen++] = (byte) ((y >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073 eventBuf[eventBufLen++] = (byte) (y & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076 // Always release all modifiers after an "up" event
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 if (pointerMask == 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080 writeModifierKeyEvents(0);
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083 os.write(eventBuf, 0, eventBufLen);
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087 // 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
1088 // 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
1089 // 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
1090 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092 void writeKeyEvent(KeyEvent evt) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094 int keyChar = evt.getKeyChar();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1095
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 // Ignore event if only modifiers were pressed.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 //
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 // 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
1101 if (keyChar == 0)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102 keyChar = KeyEvent.CHAR_UNDEFINED;
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 if (keyChar == KeyEvent.CHAR_UNDEFINED) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 int code = evt.getKeyCode();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 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
1107 || code == KeyEvent.VK_META || code == KeyEvent.VK_ALT)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108 return;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112 // Key press or key release?
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115 boolean down = (evt.getID() == KeyEvent.KEY_PRESSED);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1116
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1117 int key;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1118 if (evt.isActionKey()) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119
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 // 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
1122 // If not then just ignore the event.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1123 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1124
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1125 switch (evt.getKeyCode()) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1126 case KeyEvent.VK_HOME:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1127 key = 0xff50;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1128 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1129 case KeyEvent.VK_LEFT:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1130 key = 0xff51;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1131 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1132 case KeyEvent.VK_UP:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 key = 0xff52;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1134 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135 case KeyEvent.VK_RIGHT:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1136 key = 0xff53;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1137 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138 case KeyEvent.VK_DOWN:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1139 key = 0xff54;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1140 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141 case KeyEvent.VK_PAGE_UP:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1142 key = 0xff55;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1143 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 case KeyEvent.VK_PAGE_DOWN:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1145 key = 0xff56;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1146 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1147 case KeyEvent.VK_END:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1148 key = 0xff57;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1149 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1150 case KeyEvent.VK_INSERT:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1151 key = 0xff63;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1153 case KeyEvent.VK_F1:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154 key = 0xffbe;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1156 case KeyEvent.VK_F2:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 key = 0xffbf;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 case KeyEvent.VK_F3:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 key = 0xffc0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 case KeyEvent.VK_F4:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 key = 0xffc1;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 case KeyEvent.VK_F5:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166 key = 0xffc2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 case KeyEvent.VK_F6:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169 key = 0xffc3;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171 case KeyEvent.VK_F7:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 key = 0xffc4;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174 case KeyEvent.VK_F8:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 key = 0xffc5;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 case KeyEvent.VK_F9:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178 key = 0xffc6;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 case KeyEvent.VK_F10:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 key = 0xffc7;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1183 case KeyEvent.VK_F11:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184 key = 0xffc8;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1185 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 case KeyEvent.VK_F12:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187 key = 0xffc9;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 default:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 return;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 // 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
1197 // through.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198 // 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
1199 // 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
1200 // Anything else we ignore.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203 key = keyChar;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205 if (key < 0x20) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 if (evt.isControlDown()) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207 key += 0x60;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208 } else {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 switch (key) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 case KeyEvent.VK_BACK_SPACE:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 key = 0xff08;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213 case KeyEvent.VK_TAB:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1214 key = 0xff09;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1215 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216 case KeyEvent.VK_ENTER:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1217 key = 0xff0d;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1218 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219 case KeyEvent.VK_ESCAPE:
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220 key = 0xff1b;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1221 break;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1222 }
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 } else if (key == 0x7f) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 // Delete
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226 key = 0xffff;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227 } else if (key > 0xff) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228 // 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
1229 // 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
1230 // 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
1231 // Also, we pass through foreign currency keysyms
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1232 // (0x20a0..0x20af).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233 if ((key < 0xff00 || key > 0xffff)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1234 && !(key >= 0x20a0 && key <= 0x20af))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1235 return;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1236 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1237 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239 // 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
1240 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
1241 (key == 0xe4) || (key == 0xc4) || // XK_adiaeresis /
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1242 // XK_Adiaeresis
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1243 (key == 0xf6) || (key == 0xd6) || // XK_odiaeresis /
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1244 // XK_Odiaeresis
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245 (key == 0xa7) || (key == 0xbd) || // XK_section / XK_onehalf
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1246 (key == 0xa3)) { // XK_sterling
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1247 // 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
1248 // 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
1249 // keys)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1250 if (down)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1251 brokenKeyPressed = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1252
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253 if (!down && !brokenKeyPressed) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1254 // 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
1255 // a press. Fake it.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1256 eventBufLen = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1257 writeModifierKeyEvents(evt.getModifiers());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1258 writeKeyEvent(key, true);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1259 os.write(eventBuf, 0, eventBufLen);
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262 if (!down)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1263 brokenKeyPressed = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266 eventBufLen = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267 writeModifierKeyEvents(evt.getModifiers());
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1268 writeKeyEvent(key, down);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1269
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 // Always release all modifiers after an "up" event
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1271 if (!down)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1272 writeModifierKeyEvents(0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274 os.write(eventBuf, 0, eventBufLen);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1275 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1276
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1277 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1278 // 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
1279 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1280
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1281 void writeKeyEvent(int keysym, boolean down) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282 eventBuf[eventBufLen++] = (byte) KeyboardEvent;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283 eventBuf[eventBufLen++] = (byte) (down ? 1 : 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284 eventBuf[eventBufLen++] = (byte) 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1285 eventBuf[eventBufLen++] = (byte) 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 eventBuf[eventBufLen++] = (byte) ((keysym >> 24) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287 eventBuf[eventBufLen++] = (byte) ((keysym >> 16) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 eventBuf[eventBufLen++] = (byte) ((keysym >> 8) & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 eventBuf[eventBufLen++] = (byte) (keysym & 0xff);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 }
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 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293 // 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
1294 //
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 int oldModifiers = 0;
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 void writeModifierKeyEvents(int newModifiers) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1299 if ((newModifiers & CTRL_MASK) != (oldModifiers & CTRL_MASK))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1300 writeKeyEvent(0xffe3, (newModifiers & CTRL_MASK) != 0);
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 if ((newModifiers & SHIFT_MASK) != (oldModifiers & SHIFT_MASK))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303 writeKeyEvent(0xffe1, (newModifiers & SHIFT_MASK) != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1305 if ((newModifiers & META_MASK) != (oldModifiers & META_MASK))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 writeKeyEvent(0xffe7, (newModifiers & META_MASK) != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308 if ((newModifiers & ALT_MASK) != (oldModifiers & ALT_MASK))
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1309 writeKeyEvent(0xffe9, (newModifiers & ALT_MASK) != 0);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311 oldModifiers = newModifiers;
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 // 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
1316 // method assumes the recording is on (rec != null).
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
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1319 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
1320 Deflater deflater = new Deflater();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1321 deflater.setInput(data, off, len);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1322 int bufSize = len + len / 100 + 12;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1323 byte[] buf = new byte[bufSize];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1324 deflater.finish();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1325 int compressedSize = deflater.deflate(buf);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326 recordCompactLen(compressedSize);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 rec.write(buf, 0, compressedSize);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 }
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 void recordCompressedData(byte[] data) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1331 recordCompressedData(data, 0, data.length);
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
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 // 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
1336 // 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
1337 // (rec != null).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1338 //
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 void recordCompactLen(int len) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 byte[] buf = new byte[3];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1342 int bytes = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1343 buf[bytes++] = (byte) (len & 0x7F);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1344 if (len > 0x7F) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1345 buf[bytes - 1] |= 0x80;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1346 buf[bytes++] = (byte) (len >> 7 & 0x7F);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1347 if (len > 0x3FFF) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1348 buf[bytes - 1] |= 0x80;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1349 buf[bytes++] = (byte) (len >> 14 & 0xFF);
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 rec.write(buf, 0, bytes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1353 }
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 public void startTiming() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1356 timing = true;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1357
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1358 // 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
1359
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1360 if (timeWaitedIn100us > 10000) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361 timedKbits = timedKbits * 10000 / timeWaitedIn100us;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 timeWaitedIn100us = 10000;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1364 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1366 public void stopTiming() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1367 timing = false;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1368 if (timeWaitedIn100us < timedKbits / 2)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1369 timeWaitedIn100us = timedKbits / 2; // upper limit 20Mbit/s
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1370 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1371
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1372 public long kbitsPerSecond() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1373 return timedKbits * 10000 / timeWaitedIn100us;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1374 }
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 public long timeWaited() {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1377 return timeWaitedIn100us;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1378 }
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 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1381 // 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
1382 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1383 // 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
1384 // used to estimate data throughput.
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 public void readFully(byte b[]) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1388 readFully(b, 0, b.length);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1389 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1390
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1391 long before = System.currentTimeMillis();
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1392
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1393 public void readFully(byte b[], int off, int len) throws IOException {
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1394 // long before = 0;
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1395 if (timing)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1396 before = System.currentTimeMillis();
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 is.readFully(b, off, len);
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1399
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1400 /*
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1401 * 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
1402 * b[7] = (byte)0; System.out.println("----------------------"); }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1403 */
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1404 // System.out.println("Blength:"+b.length);
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1405 // for(int i=0 ; i<=b.length ; i++) {
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1406 // if(i>b.length/2)
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1407 // b[i] = 10;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1408 // }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1409
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1410 /*
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1411 * if (timing) { long after = System.currentTimeMillis(); long
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1412 * newTimeWaited = (after - before) * 10; int newKbits = len * 8 / 1000;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1413 *
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1414 * // limit rate to between 10kbit/s and 40Mbit/s
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1415 *
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1416 * if (newTimeWaited > newKbits * 1000) newTimeWaited = newKbits * 1000;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1417 * if (newTimeWaited < newKbits / 4) newTimeWaited = newKbits / 4;
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1418 *
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1419 * timeWaitedIn100us += newTimeWaited; timedKbits += newKbits; before =
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1420 * after; }
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1421 */
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1422 numBytesRead += len;
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1423 // System.out.println("numBytesRead:"+numBytesRead);
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1424 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1425
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1426 final int available() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1427 return is.available();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1428 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1429
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1430 // FIXME: DataInputStream::skipBytes() is not guaranteed to skip
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1431 // 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
1432 final int skipBytes(int n) throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1433 int r = is.skipBytes(n);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1434 numBytesRead += r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1435 return r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1436 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1437
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1438 final int readU8() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1439 int r = is.readUnsignedByte();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1440 numBytesRead++;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1441
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1442 return r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1443 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1444
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1445 final int readU16() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1446 int r = is.readUnsignedShort();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1447 numBytesRead += 2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1448 return r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1449 }
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 final int readU32() throws IOException {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1452 int r = is.readInt();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1453 numBytesRead += 4;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1454 return r;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1455 }
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1456
3
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1457 public LinkedList<ByteBuffer> blockingUpdateRectangle(
3b341997141a broadcast socket trying
one
parents: 2
diff changeset
1458 LinkedList<ByteBuffer> input, int w, int h) {
2
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1459
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1460 return null;
5d72f4c7371d befor change
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1461 }
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1462 }