Skip to content

Commit e19b3dd

Browse files
committed
4.2.0
1 parent e5ae0a8 commit e19b3dd

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Java SE 6+/Android 4.1+ WebSocket client and server package, MIT (c) 2020-2024 @miktim<br/>
1+
## Java SE 6+/Android 4.1+ WebSocket client and server package, MIT (c) 2020-2025 @miktim<br/>
22
### Release notes:
33

44
\- RFC 6455 compliant package ( [https://datatracker.ietf.org/doc/html/rfc6455/](https://datatracker.ietf.org/doc/html/rfc6455/) );
@@ -9,7 +9,6 @@
99
\- WebSocket extensions ( Per-Message Deflate, ... ) are not supported;
1010
\- supports cleartext/TLS connections (without tunneling);
1111
\- client supports Internationalized Domain Names (IDNs);
12-
\- thread safe connections;
1312
\- stream-based messaging.
1413

1514
The ./dist/websocket-... jar file was built with debug info using JDK 1.8 for the target JRE 1.6.
@@ -22,7 +21,7 @@ Overview of the package in the file ./README.txt .
2221
```
2322
//... some code
2423
// create server side connection handler
25-
WsConnection.Handler handler = new WsConnection.EventHandler() {
24+
WsConnection.Handler handler = new WsConnection.Handler() {
2625
@Override
2726
onOpen(WsConnection conn, String subProtocol) {
2827
conn.send("Hello, Client!");
@@ -63,7 +62,7 @@ Overview of the package in the file ./README.txt .
6362
```
6463
//... some code
6564
// create client connection handler
66-
WsConnection.Handler handler = new WsConnection.EventHandler() {
65+
WsConnection.Handler handler = new WsConnection.Handler() {
6766
@Override
6867
onOpen(WsConnection conn, String subProtocol) {
6968
conn.send("Hello, Server!");

README.txt

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@ Release notes:
77
- WebSocket extensions (Per-Message Deflate, ...) are not supported;
88
- supports cleartext/TLS connections (without tunneling);
99
- client supports Internationalized Domain Names (IDNs);
10-
- thread safe connections;
1110
- stream-based messaging.
1211

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
1413

1514
package org.miktim.websocket
1615

1716
Overview:
1817

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+
1926
Class WebSocket:
20-
Servers and client connections creator.
27+
Creator of WebSocket servers or client connections.
2128

2229
Constant:
2330
static final String VERSION = "4.2.0";
@@ -47,7 +54,7 @@ Overview:
4754
WsServer SecureServer(int port, WsConnection.Handler handler, WsParameters wsp) throws IOException, GeneralSecurityException;
4855
- creates TLS connections server
4956

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.
5158

5259
WsConnection connect(String uri, WsConnection.Handler handler, WsParameters wsp) throws URISyntaxException, IOException, GeneralSecurityException;
5360
- creates and starts a client connection;
@@ -57,7 +64,7 @@ Overview:
5764

5865
InetAddress getBindAddress();
5966
WsServer[] listServers();
60-
- lists active/terminated servers.
67+
- lists active/interrupted servers.
6168
WsConnection[] listConnections();
6269
- lists active connections.
6370

@@ -67,9 +74,11 @@ Overview:
6774

6875

6976
Class WsServer extends Thread:
70-
77+
This class implements a WebSocket server for cleartext or TLS connections.
78+
7179
Methods:
7280
WsServer setHandler(WsServer.Handler handler);
81+
- replaces the default handler;
7382
void start();
7483
- inherited, starts server
7584
WsServer launch();
@@ -78,7 +87,7 @@ Overview:
7887
boolean isOpen();
7988
- returns the running state
8089
boolean isSecure();
81-
- is secure server
90+
- is TLS connections server
8291
boolean isInterrupted();
8392
- returns true if the server was interrupted by a method or due to a server socket exception
8493
Exception getError();
@@ -91,30 +100,36 @@ Overview:
91100
WsParameters getParameters();
92101
- returns server connection parameters
93102
WsConnection[] listConnections();
94-
- returns a list of active connections
103+
- returns the list of active connections
95104

96105
void close();
97106
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)
99108
void interrupt();
100109
- interrupts the server, associated connections stay alive and can be closed in the usual way
101110

102111

103112
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.
105114

106115
Methods:
107116
void onStart(WsServer server);
117+
- called when the server is started
108118

109119
boolean onAccept(WsServer server, WsConnection conn);
110120
- 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+
112124

113125
void onStop(WsServer server, Exception error);
126+
- called when the server is closed or interrupted;
114127
- error is a ServerSocket exception or null
115128

116129

117130
Class WsConnection extends Thread:
131+
Client side or server side connection.
132+
118133
Constant:
119134
MESSAGE_QUEUE_CAPACITY = 3
120135
- overflow of the incoming message queue leads to an error and connection closure with status code 1008 (POLICY_VIOLATION)
@@ -128,7 +143,7 @@ Overview:
128143
- send binary data
129144

130145
boolean isClientSide();
131-
- returns true for client connections
146+
- returns true for client side connections
132147
boolean isOpen();
133148
- WebSocket connection is open
134149
boolean isSecure();
@@ -140,26 +155,28 @@ Overview:
140155
WsConnection[] listConnections()
141156
- the client connection returns only itself
142157
String getSSLSessionProtocol()
143-
- returns SSL protocol or null
158+
- returns SSL protocol or null for cleartext connection
144159
WsStatus getStatus();
145160
- returns the connection status, syncs with a client WebSocket handshake
146161
String getSubProtocol();
147162
- returns null or handshaked WebSocket subprotocol
148163
String getPeerHost();
149164
- returns remote host name or null
165+
Socket getSocket();
166+
- returns connection socket
150167
int getPort();
151168
- returns connected port
152169
String getPath();
153170
- returns http request path or null
154171
String getQuery();
155172
- returns http request query or null
156173
WsParameters getParameters();
174+
- returns connection parameters
157175

158176
void close();
159177
- closes connection with status code 1005 (NO_STATUS)
160178
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;
163180
- a reason that is longer than 123 BYTES is truncated;
164181
- the method blocks outgoing messages (sending methods throw IOException);
165182
- isOpen() returns false;
@@ -170,7 +187,7 @@ Overview:
170187
There are two scenarios for handling events:
171188
- onError - onClose, when the SSL/WebSocket handshake failed;
172189
- 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.
174191

175192
Methods:
176193
void onOpen(WsConnection conn, String subProtocol);
@@ -188,28 +205,28 @@ Overview:
188205

189206

190207
Class WsParameters:
191-
WebSocket connection parameters
208+
WebSocket connection creation and execution time parameters
192209

193210
Constructor:
194211
WsParameters();
195212

196213
Methods:
197214
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;
199216
String[] getSubProtocols();
200217
- null is default
201218
WsParameters setHandshakeSoTimeout(int millis);
202219
- sets a timeout for opening/closing a WebSocket connection
203220
int getHandshakeSoTimeout();
204221
WsParameters setConnectionSoTimeout(int millis, boolean pingEnabled)
205222
- 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)
207224

208225
int getConnectionSoTimeout();
209226
boolean isPingEnabled();
210-
-enabled by default
227+
- enabled by default
211228
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
213230
int getPayloadBufferLength();
214231
WsParameters setMaxMessageLength(int len);
215232
- 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:
229246

230247

231248
Class WsStatus:
232-
Connection status
249+
The status of the WebSocket connection
233250

234251
Fields:
235252
int code; // closing code (0, 1000-4999)
236253
String reason; // closing reason (max length 123 BYTES)
237254
boolean wasClean; // WebSocket closing handshake completed cleanly
238255
boolean remotely; // closed remotely
239-
Throwable error; // closing exception or null
256+
Throwable error; // connection execution exception or null
240257

241258

242259
Usage examples see in:

0 commit comments

Comments
 (0)