Skip to content
This repository was archived by the owner on Nov 2, 2020. It is now read-only.

Commit b68c9b9

Browse files
committed
Updated README
1 parent d100416 commit b68c9b9

File tree

1 file changed

+9
-182
lines changed

1 file changed

+9
-182
lines changed

docs/README.md

Lines changed: 9 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1,192 +1,19 @@
11
<h1 align="center">ClusterWS Java Client</h1>
2-
<h6 align="center">WebSocket & Node JS Cluster</h6>
2+
<h6 align="center">Build Scalable Node.js WebSocket Applications</h6>
33

44
<p align="center">
5-
<img alt="Node.js" src="http://u.cubeupload.com/goriunovd/clusterWS.png" width="560"/>
5+
<img src="https://cdn.rawgit.com/goriunov/159120ca6a883d8d4e75543ec395d361/raw/f4c3c36ac1ab75beedcf73312272b60dac33ecfa/clusterws.svg" width="500">
66
</p>
77

88
<p align="center">
99
<a title="JitPack Version" href="https://jitpack.io/#ClusterWS/ClusterWS-Client-Java"><img src="https://jitpack.io/v/ClusterWS/ClusterWS-Client-Java.svg"></a>
1010
</p>
1111

12-
## Overview
13-
This is official Java client for [ClusterWS](https://github.com/ClusterWS/ClusterWS).
14-
15-
[ClusterWS](https://github.com/ClusterWS/ClusterWS) - is a minimal **Node JS http & real-time** framework which allows to scale WebSocket ([uWS](https://github.com/uNetworking/uWebSockets) - one of the fastest WebSocket libraries) between **Workers** in [Node JS Cluster](https://nodejs.org/api/cluster.html) and utilize all available CPU.
16-
17-
**This library requires [ClusterWS](https://github.com/ClusterWS/ClusterWS) on the server**
18-
19-
## Installation
20-
### Maven
21-
22-
```xml
23-
<repositories>
24-
<repository>
25-
<id>jitpack.io</id>
26-
<url>https://jitpack.io</url>
27-
</repository>
28-
</repositories>
29-
30-
<dependency>
31-
<groupId>com.github.ClusterWS</groupId>
32-
<artifactId>ClusterWS-Client-Java</artifactId>
33-
<version>1.5.0</version>
34-
</dependency>
35-
```
36-
37-
38-
### Gradle
39-
40-
```Gradle
41-
allprojects {
42-
repositories {
43-
maven { url 'https://jitpack.io' }
44-
}
45-
}
46-
47-
dependencies {
48-
compile 'com.github.ClusterWS:ClusterWS-Client-Java:1.5.0'
49-
}
50-
```
51-
52-
53-
## Socket
54-
### 1. Connecting
55-
You can connect to the server with the following code:
56-
```java
57-
/**
58-
First parameter: string - url of the server without http or https. (must be provided)
59-
Second parameter: string - port of the server. (must be provided)
60-
*/
61-
ClusterWS clusterWS = new ClusterWS("localhost","80");
62-
clusterWS.connect();
63-
64-
```
65-
66-
in case if you are using this library on Android you have to connect on separate thread or use method connectAsynchronously:
67-
```java
68-
ClusterWS clusterWS = new ClusterWS("localhost","80");
69-
clusterWS.connectAsynchronously();
70-
```
71-
72-
If you want to set auto reconnection use setReconnection method
73-
```java
74-
/**
75-
First parameter: boolean - allow to auto-reconnect to the server on lost connection. (default false)
76-
Second parameter: int - how long min time wait. (default 1000) in ms
77-
Third parameter: int - how long max time wait. (default 5000) in ms
78-
Fourth parameter: int - how many times to try, 0 means without limit. (default 0)
79-
*/
80-
clusterWS.setReconnection(true, 1000, 2000, 3);
81-
```
82-
83-
*Auto reconnect count random time between Max and Min interval value this will reduce amount of users which are connection at the same time on reconnection and reduce server load on restart of the server*
84-
85-
### 2. Listen on events
86-
To listen on events from the server you should use `on` method witch is provided by `clusterWS`
87-
```java
88-
/**
89-
event name: string - can be any string you wish
90-
data: any - is what you send from the client
91-
*/
92-
clusterWS.on("event name", new EmitterListener() {
93-
@Override
94-
public void onDataReceived(Object data) {
95-
// in here you can write any logic
96-
}
97-
});
98-
```
99-
100-
*Also `clusterWS` gets **Reserved Events** such as `'onConnected'`, `'onDisconnected'` and `'onConnectError'`*
101-
```java
102-
clusterWS.setClusterWSListener(new ClusterWSListener() {
103-
@Override
104-
public void onConnected(final ClusterWS socket) {
105-
// in here you can write any logic
106-
}
107-
108-
@Override
109-
public void onConnectError(ClusterWS socket, WebSocketException exception) {
110-
// in here you can write any logic
111-
}
112-
113-
@Override
114-
public void onDisconnected(ClusterWS socket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) {
115-
// in here you can write any logic
116-
}
117-
});
118-
```
119-
120-
### 3. Send events
121-
To send events to the server use `send` method witch is provided by `clusterWS`
122-
```java
123-
/**
124-
event name: string - can be any string you wish (client must listen on this event name)
125-
data: any - is what you want to send to the client
126-
*/
127-
clusterWS.send("event name",data);
128-
129-
```
130-
131-
*Avoid emitting **Reserved Events** such as `'connect'`, `'connection'`, `'disconnect'` and `'error'`. Also avoid emitting event and events with `'#'` at the start.*
132-
133-
## Pub/Sub
134-
You can `subscribe`, `watch`, `unsubscribe`, `publish` and `getChannelByName` to/from the channels
135-
```java
136-
/**
137-
channel name: string - can be any string you wish
138-
*/
139-
Channel channel = clusterWS.subscribe("channel name");
140-
141-
/**
142-
channelName: string - name of the channel to which data was sent to
143-
data: any - is what you get when you or some one else publish to the channel
144-
*/
145-
channel.watch(new Channel.ChannelListener() {
146-
@Override
147-
public void onDataReceived(String channelName, Object data) {
148-
// in here you can write any logic
149-
}
150-
})
151-
152-
/**
153-
data: any - is what you want to publish to the channel (everyone who is subscribed will get it)
154-
*/
155-
channel.publish(data);
156-
157-
/**
158-
This method is used to unsubscribe from the channel
159-
*/
160-
channel.unsubscribe();
161-
162-
/**
163-
Also you can chain everything in one expression
164-
*/
165-
Channel channel = clusterWS.subscribe("channel name").watch(new Channel.ChannelListener() {
166-
@Override
167-
public void onDataReceived(String channelName, Object data) {
168-
// in here you can write any logic
169-
}
170-
}).publish(data);
171-
172-
/**
173-
You can get channel by channel name only if you were subscribed before
174-
*/
175-
176-
clusterWS.getChannelByName("channel name");
177-
178-
/**
179-
You can get all channels as an array by using getChannels method
180-
*/
181-
clusterWS.getChannels();
182-
```
183-
184-
**To make sure that user is connected to the server before subscribing, do it on `onConnected` event or on any other events which you emit from the server, otherwise subscription may not work properly**
185-
186-
## See also
187-
* [Medium ClusterWS](https://medium.com/clusterws)
188-
189-
190-
#### *Docs are still under development. If you have found any errors please submit pull request or leave issue*
12+
<p align="center">
13+
<i>Official Java Client library for <a href="https://github.com/ClusterWS/ClusterWS">ClusterWS</a> - lightweight, fast and powerful framework for building horizontally & vertically scalable WebSocket applications in Node.js</i>
14+
</p>
19115

192-
## Good luck and Have fun :balloon: :running:
16+
<h1></h1>
17+
<h3 align="center">
18+
<a href="https://github.com/ClusterWS/ClusterWS-Client-Java/wiki"><strong>ClusterWS JavaScript Client Documentation</strong></a>
19+
</h3>

0 commit comments

Comments
 (0)