update README
This commit is contained in:
42
README.md
42
README.md
@@ -13,7 +13,7 @@ The latest artifact is available on Maven Central. Add the following dependency
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.nkzawa</groupId>
|
<groupId>com.github.nkzawa</groupId>
|
||||||
<artifactId>engine.io-client</artifactId>
|
<artifactId>engine.io-client</artifactId>
|
||||||
<version>0.1.3</version>
|
<version>0.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
```
|
```
|
||||||
@@ -22,29 +22,26 @@ The latest artifact is available on Maven Central. Add the following dependency
|
|||||||
Engine.IO-client.java has the similar api with the JS client. You can use `Socket` to connect:
|
Engine.IO-client.java has the similar api with the JS client. You can use `Socket` to connect:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
socket = new Socket("ws://localhost") {
|
socket = new Socket("ws://localhost");
|
||||||
|
socket.on(Socket.EVENT_OPEN, new Emitter.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onopen() {
|
public void call(Object... args) {
|
||||||
socket.send("hi");
|
socket.send("hi");
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
@Override
|
|
||||||
public void onmessage(String data) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onclose() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onerror(Exception err) {}
|
|
||||||
};
|
|
||||||
socket.open();
|
socket.open();
|
||||||
```
|
```
|
||||||
|
|
||||||
You can receive events as follows:
|
You can listen events as follows:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
socket.on(Socket.EVENT_ERROR, new Emitter.Listener() {
|
socket.on(Socket.EVENT_MESSAGE, new Emitter.Listener() {
|
||||||
|
@Override
|
||||||
|
public void call(Object... args) {
|
||||||
|
String data = (String)args[0];
|
||||||
|
}
|
||||||
|
}).on(Socket.EVENT_ERROR, new Emitter.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void call(Object... args) {
|
public void call(Object... args) {
|
||||||
Exception err = (Exception)args[0];
|
Exception err = (Exception)args[0];
|
||||||
@@ -58,26 +55,27 @@ How to set options:
|
|||||||
opts = new Socket.Options();
|
opts = new Socket.Options();
|
||||||
opts.transports = new String[] {WebSocket.NAME};
|
opts.transports = new String[] {WebSocket.NAME};
|
||||||
|
|
||||||
socket = new Socket(opts) { ... };
|
socket = new Socket(opts);
|
||||||
```
|
```
|
||||||
|
|
||||||
Sending and receiving binary data:
|
Sending and receiving binary data:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
socket = new Socket() {
|
socket = new Socket();
|
||||||
|
socket.on(Socket.EVENT_OPEN, new Emitter.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onopen() {
|
public void call(Object... args) {
|
||||||
// send binary data
|
// send binary data
|
||||||
byte[] data = new byte[42];
|
byte[] data = new byte[42];
|
||||||
socket.send(data);
|
socket.send(data);
|
||||||
}
|
}
|
||||||
|
}).on(Socket.EVENT_MESSAGE, new Emitter.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onmessage(byte[] data) {
|
public void call(Object... args) {
|
||||||
// receive binary data
|
// receive binary data
|
||||||
|
byte[] data = (byte[])args[0];
|
||||||
}
|
}
|
||||||
...
|
});
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Extra features only for Java client
|
### Extra features only for Java client
|
||||||
|
|||||||
Reference in New Issue
Block a user