@@ -7,17 +7,24 @@ Release notes:
7
7
- WebSocket extensions (Per-Message Deflate, ...) are not supported;
8
8
- supports cleartext/TLS connections (without tunneling);
9
9
- client supports Internationalized Domain Names (IDNs);
10
- - thread safe connections;
11
10
- stream-based messaging.
12
11
13
- The jar ./dist/websocket-... file was generated with debugging info using JDK1.8.0 for target JDK1.6
12
+ The jar ./dist/websocket-... file was generated with debugging info using JDK1.8 for target JDK1.6
14
13
15
14
package org.miktim.websocket
16
15
17
16
Overview:
18
17
18
+ Class WebSocket - creator of WebSocket servers or client connections;
19
+ Class WsServer - implements a WebSocket server for cleartext or TLS connections;
20
+ Interface WsServer.Handler - server event handler;
21
+ Class WsConnection - implements a WebSocket connection on the server or client side;
22
+ Interface WsConnection.Handler - connection event handler;
23
+ Class WsParameters - WebSocket connection creation and execution time parameters;
24
+ Class WsStatus - WebSocket connection status.
25
+
19
26
Class WebSocket:
20
- Servers and client connections creator .
27
+ Creator of WebSocket servers or client connections.
21
28
22
29
Constant:
23
30
static final String VERSION = "4.2.0";
@@ -47,7 +54,7 @@ Overview:
47
54
WsServer SecureServer(int port, WsConnection.Handler handler, WsParameters wsp) throws IOException, GeneralSecurityException;
48
55
- creates TLS connections server
49
56
50
- Servers are created using a "dumb" server handler. You can set your own handler or start the server immediately.
57
+ Servers are created using a default server handler. You can set your own handler or start the server immediately. The default handler's only action is printStackTrace in case of a ServerSocket error .
51
58
52
59
WsConnection connect(String uri, WsConnection.Handler handler, WsParameters wsp) throws URISyntaxException, IOException, GeneralSecurityException;
53
60
- creates and starts a client connection;
@@ -57,7 +64,7 @@ Overview:
57
64
58
65
InetAddress getBindAddress();
59
66
WsServer[] listServers();
60
- - lists active/terminated servers.
67
+ - lists active/interrupted servers.
61
68
WsConnection[] listConnections();
62
69
- lists active connections.
63
70
@@ -67,9 +74,11 @@ Overview:
67
74
68
75
69
76
Class WsServer extends Thread:
70
-
77
+ This class implements a WebSocket server for cleartext or TLS connections.
78
+
71
79
Methods:
72
80
WsServer setHandler(WsServer.Handler handler);
81
+ - replaces the default handler;
73
82
void start();
74
83
- inherited, starts server
75
84
WsServer launch();
@@ -78,7 +87,7 @@ Overview:
78
87
boolean isOpen();
79
88
- returns the running state
80
89
boolean isSecure();
81
- - is secure server
90
+ - is TLS connections server
82
91
boolean isInterrupted();
83
92
- returns true if the server was interrupted by a method or due to a server socket exception
84
93
Exception getError();
@@ -91,30 +100,36 @@ Overview:
91
100
WsParameters getParameters();
92
101
- returns server connection parameters
93
102
WsConnection[] listConnections();
94
- - returns a list of active connections
103
+ - returns the list of active connections
95
104
96
105
void close();
97
106
void close(String closeReason);
98
- - close methods also closes all associated connections ( code GOING_AWAY)
107
+ - close methods also closes all active connections with code 1001 ( GOING_AWAY)
99
108
void interrupt();
100
109
- interrupts the server, associated connections stay alive and can be closed in the usual way
101
110
102
111
103
112
Interface WsServer.Handler:
104
- Leave handler as soon as possible .
113
+ The default handler's only action is printStackTrace in case of a ServerSocket error .
105
114
106
115
Methods:
107
116
void onStart(WsServer server);
117
+ - called when the server is started
108
118
109
119
boolean onAccept(WsServer server, WsConnection conn);
110
120
- called BEFORE WebSocket connection handshake;
111
- - the returned value of true means approval of the connection, the value of false means the closure of the client connection
121
+ - the returned value of true means approval of the connection, the value of false means the closure of the client connection;
122
+ - leave method as soon as possible
123
+
112
124
113
125
void onStop(WsServer server, Exception error);
126
+ - called when the server is closed or interrupted;
114
127
- error is a ServerSocket exception or null
115
128
116
129
117
130
Class WsConnection extends Thread:
131
+ Client side or server side connection.
132
+
118
133
Constant:
119
134
MESSAGE_QUEUE_CAPACITY = 3
120
135
- overflow of the incoming message queue leads to an error and connection closure with status code 1008 (POLICY_VIOLATION)
@@ -128,7 +143,7 @@ Overview:
128
143
- send binary data
129
144
130
145
boolean isClientSide();
131
- - returns true for client connections
146
+ - returns true for client side connections
132
147
boolean isOpen();
133
148
- WebSocket connection is open
134
149
boolean isSecure();
@@ -140,26 +155,28 @@ Overview:
140
155
WsConnection[] listConnections()
141
156
- the client connection returns only itself
142
157
String getSSLSessionProtocol()
143
- - returns SSL protocol or null
158
+ - returns SSL protocol or null for cleartext connection
144
159
WsStatus getStatus();
145
160
- returns the connection status, syncs with a client WebSocket handshake
146
161
String getSubProtocol();
147
162
- returns null or handshaked WebSocket subprotocol
148
163
String getPeerHost();
149
164
- returns remote host name or null
165
+ Socket getSocket();
166
+ - returns connection socket
150
167
int getPort();
151
168
- returns connected port
152
169
String getPath();
153
170
- returns http request path or null
154
171
String getQuery();
155
172
- returns http request query or null
156
173
WsParameters getParameters();
174
+ - returns connection parameters
157
175
158
176
void close();
159
177
- closes connection with status code 1005 (NO_STATUS)
160
178
void close(int statusCode, String reason);
161
- - the status code outside 1000-4999 will be replaced with 1005 (NO_STATUS),
162
- the reason is ignored;
179
+ - the status code outside 1000-4999 will be replaced with 1005 (NO_STATUS), the reason is ignored;
163
180
- a reason that is longer than 123 BYTES is truncated;
164
181
- the method blocks outgoing messages (sending methods throw IOException);
165
182
- isOpen() returns false;
@@ -170,7 +187,7 @@ Overview:
170
187
There are two scenarios for handling events:
171
188
- onError - onClose, when the SSL/WebSocket handshake failed;
172
189
- onOpen - [onMessage - onMessage - ...] - [onError] - onClose.
173
- The handler's RuntimeException only calls the printStackTrace() function. The connection interrupted .
190
+ The handler's RuntimeException only calls the printStackTrace() function. The connection terminated .
174
191
175
192
Methods:
176
193
void onOpen(WsConnection conn, String subProtocol);
@@ -188,28 +205,28 @@ Overview:
188
205
189
206
190
207
Class WsParameters:
191
- WebSocket connection parameters
208
+ WebSocket connection creation and execution time parameters
192
209
193
210
Constructor:
194
211
WsParameters();
195
212
196
213
Methods:
197
214
WsParameters setSubProtocols(String[] subps);
198
- - sets WebSocket subProtocols in preferred order;
215
+ - sets the WebSocket subprotocol required by the client or supported by the server in the preferred order;
199
216
String[] getSubProtocols();
200
217
- null is default
201
218
WsParameters setHandshakeSoTimeout(int millis);
202
219
- sets a timeout for opening/closing a WebSocket connection
203
220
int getHandshakeSoTimeout();
204
221
WsParameters setConnectionSoTimeout(int millis, boolean pingEnabled)
205
222
- sets data exchange timeout;
206
- - if the timeout is exceeded and ping is disabled, the connection is terminated with status code 1001 (GOING_AWAY)
223
+ - if the timeout is exceeded and ping is disabled, the connection is closed with status code 1001 (GOING_AWAY)
207
224
208
225
int getConnectionSoTimeout();
209
226
boolean isPingEnabled();
210
- -enabled by default
227
+ - enabled by default
211
228
WsParameters setPayloadBufferLength(int len);
212
- - sets outgoing messages max payload length, min len = 125 bytes
229
+ - sets the maximum payload length of the outgoing message frames, the minimum length is 125 bytes
213
230
int getPayloadBufferLength();
214
231
WsParameters setMaxMessageLength(int len);
215
232
- sets incoming messages max length. If exceeded, the connection will be terminated with the 1009 (MESSAGE_TOO_BIG) status code
@@ -229,14 +246,14 @@ Overview:
229
246
230
247
231
248
Class WsStatus:
232
- Connection status
249
+ The status of the WebSocket connection
233
250
234
251
Fields:
235
252
int code; // closing code (0, 1000-4999)
236
253
String reason; // closing reason (max length 123 BYTES)
237
254
boolean wasClean; // WebSocket closing handshake completed cleanly
238
255
boolean remotely; // closed remotely
239
- Throwable error; // closing exception or null
256
+ Throwable error; // connection execution exception or null
240
257
241
258
242
259
Usage examples see in:
0 commit comments