Skip to content

Commit 3b90d17

Browse files
committed
Update README
1 parent a5405b2 commit 3b90d17

File tree

1 file changed

+40
-57
lines changed

1 file changed

+40
-57
lines changed

README.md

Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,23 @@ Implemented using `BasicListener` interface
6363
```java
6464
socket.setListener(new BasicListener() {
6565

66-
public void onConnected(Socket socket,Map<String, List<String>> headers) {
66+
public void onConnected(Socket socket, Map<String, List<String>> headers) {
6767
System.out.println("Connected to endpoint");
6868
}
6969

70-
public void onDisconnected(Socket socket,WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) {
70+
public void onDisconnected(Socket socket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) {
7171
System.out.println("Disconnected from end-point");
7272
}
7373

74-
public void onConnectError(Socket socket,WebSocketException exception) {
74+
public void onConnectError(Socket socket, WebSocketException exception) {
7575
System.out.println("Got connect error "+ exception);
7676
}
7777

7878
public void onSetAuthToken(String token, Socket socket) {
7979
System.out.println("Token is "+ token);
8080
}
8181

82-
public void onAuthentication(Socket socket,Boolean status) {
82+
public void onAuthentication(Socket socket, Boolean status) {
8383
if (status) {
8484
System.out.println("socket is authenticated");
8585
} else {
@@ -95,57 +95,56 @@ Implemented using `BasicListener` interface
9595
- For connecting to server:
9696

9797
```java
98-
//This will send websocket handshake request to socketcluster-server
98+
// This will send websocket handshake request to socketcluster-server
9999
socket.connect();
100100
```
101101

102102
- For connecting asynchronously to server:
103103

104104
```java
105-
//This will send websocket handshake request to socketcluster-server
105+
// This will send websocket handshake request to socketcluster-server
106106
socket.connectAsync();
107107
```
108108

109109

110-
- By default reconnection to server is not enabled , to enable it :
110+
- By default reconnection to server is not enabled, to enable it:
111111

112112
```java
113-
//This will set automatic-reconnection to server with delay of 2 seconds and repeating it for 30 times
113+
// This will set automatic reconnection to server with delay of 2 seconds and repeating it for 30 times
114114
socket.setReconnection(new ReconnectStrategy().setDelay(2000).setMaxAttempts(30));
115115
socket.connect();
116116
```
117117

118118
- To disable reconnection :
119119

120-
```
120+
```java
121121
socket.setReconnection(null);
122122
```
123123

124-
- By default logging of messages is enabled ,to disable :
124+
- By default logging of messages is enabled, to disable:
125125

126-
```
126+
```java
127127
socket.disableLogging();
128128
```
129129

130130
Emitting and listening to events
131131
--------------------------------
132132
#### Event emitter
133133

134-
- eventname is name of event and message can be String, boolean, Long or JSON-object
134+
- eventname is name of event and message can be String, boolean, Long or JsonNode
135135

136136
```java
137-
socket.emit(eventname,message);
137+
socket.emit(eventname, message);
138138

139-
//socket.emit("chat","Hi");
139+
// socket.emit("chat", "Hi");
140140
```
141141

142142
- To send event with acknowledgement
143143

144144
```java
145145
socket.emit(eventname, message, new Ack() {
146-
public void call(String eventName,Object error, Object data) {
147-
//If error and data is String
148-
System.out.println("Got message for :"+eventName+" error is :"+error+" data is :"+data);
146+
public void call(String eventName, JsonNode error, JsonNode data) {
147+
System.out.println("Got message for :" + eventName + " error is: " + error + " data is:" + data);
149148
}
150149
});
151150
```
@@ -154,14 +153,12 @@ Emitting and listening to events
154153

155154
- For listening to events :
156155

157-
The object received can be String, Boolean, Long or JSONObject.
156+
The object received can be String, Boolean, Long or JsonNode.
158157

159158
```java
160159
socket.on(eventname, new Emitter.Listener() {
161-
public void call(String eventName,Object object) {
162-
163-
// Cast object to its proper datatype
164-
System.out.println("Got message for :"+eventName+" data is :"+data);
160+
public void call(String eventName, JsonNode data) {
161+
System.out.println("Got message for: " + eventName + " data is: " + data);
165162
}
166163
});
167164
```
@@ -170,27 +167,17 @@ The object received can be String, Boolean, Long or JSONObject.
170167

171168
```java
172169
socket.on(eventname, new Emitter.AckListener() {
173-
public void call(String eventName,Object object, Ack ack) {
174-
175-
// Cast object to its proper datatype
176-
System.out.println("Got message :: " + object);
177-
/...
178-
Some logic goes here
179-
.../
170+
public void call(String eventName, JsonNode object, Ack ack) {
171+
System.out.println("Got message: " + object);
172+
// ...
180173
if (error){
181-
182-
ack.call(eventName,error,null);
183-
184-
}else{
185-
186-
//Data can be of any data type
187-
188-
ack.call(eventName,null,data);
174+
ack.call(eventName, error, null);
175+
} else{
176+
ack.call(eventName, null, data);
189177
}
190178

191179
//Both error and data can be sent to server
192-
193-
ack.call(eventName,error,data);
180+
ack.call(eventName, error, data);
194181
}
195182
});
196183

@@ -219,22 +206,22 @@ Implementing Pub-Sub via channels
219206

220207
```java
221208
Socket.Channel channel = socket.createChannel(channelName);
222-
//Socket.Channel channel = socket.createChannel("yolo");
209+
// Socket.Channel channel = socket.createChannel("yolo");
223210

224211

225212
/**
226213
* without acknowledgement
227214
*/
228-
channel.subscribe();
215+
channel.subscribe();
229216

230217
/**
231218
* with acknowledgement
232219
*/
233220

234221
channel.subscribe(new Ack() {
235-
public void call(String channelName, Object error, Object data) {
222+
public void call(String channelName, JsonNode error, JsonNode data) {
236223
if (error == null) {
237-
System.out.println("Subscribed to channel "+channelName+" successfully");
224+
System.out.println("Subscribed to channel " + channelName + " successfully");
238225
}
239226
}
240227
});
@@ -243,15 +230,14 @@ Implementing Pub-Sub via channels
243230
- For getting list of created channels :
244231

245232
```java
246-
List <Socket.Channel> channels=socket.getChannels();
233+
List <Socket.Channel> channels = socket.getChannels();
247234
```
248235

249236
- To get channel by name :
250237

251238
```java
252-
Socket.Channel channel=socket.getChannelByName("yolo");
239+
Socket.Channel channel = socket.getChannelByName("yolo");
253240
//Returns null if channel of given name is not present
254-
255241
```
256242

257243

@@ -272,9 +258,9 @@ Implementing Pub-Sub via channels
272258
* with acknowledgement
273259
*/
274260
channel.publish(message, new Ack() {
275-
public void call(String channelName,Object error, Object data) {
261+
public void call(String channelName, JsonNode error, JsonNode data) {
276262
if (error == null) {
277-
System.out.println("Published message to channel "+channelName+" successfully");
263+
System.out.println("Published message to channel " + channelName + " successfully");
278264
}
279265
}
280266
});
@@ -287,31 +273,29 @@ Implementing Pub-Sub via channels
287273

288274
```java
289275
channel.onMessage(new Emitter.Listener() {
290-
public void call(String channelName , Object object) {
291-
292-
System.out.println("Got message for channel "+channelName+" data is "+data);
293-
276+
public void call(String channelName , JsonNode object) {
277+
System.out.println("Got message for channel " + channelName + " data is " + data);
294278
}
295279
});
296280
```
297281

298282
<!--###### Pub-sub without creating channel-->
299-
#### Un-subscribing to channel
283+
#### Unsubscribing a channel
300284

301285
```java
302286

303287
/**
304288
* without acknowledgement
305289
*/
306290

307-
channel.unsubscribe();
291+
channel.unsubscribe();
308292

309293
/**
310294
* with acknowledgement
311295
*/
312296

313297
channel.unsubscribe(new Ack() {
314-
public void call(String channelName, Object error, Object data) {
298+
public void call(String channelName, JsonNode error, JsonNode data) {
315299
if (error == null) {
316300
System.out.println("channel unsubscribed successfully");
317301
}
@@ -328,7 +312,7 @@ To get instance of `WebSocketFactory` class :
328312

329313
```java
330314

331-
WebSocketFactory factory=socket.getFactorySettings();
315+
WebSocketFactory factory = socket.getFactorySettings();
332316

333317
```
334318

@@ -384,4 +368,3 @@ Basic Authentication.
384368
settings.setCredentials(id, password);
385369
```
386370
#### Star the repo. if you love the client :).
387-

0 commit comments

Comments
 (0)