forked from socketio/socket.io-client-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConnectionFailure.java
More file actions
37 lines (31 loc) · 1.15 KB
/
ConnectionFailure.java
File metadata and controls
37 lines (31 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package io.socket.client.executions;
import io.socket.emitter.Emitter;
import io.socket.client.IO;
import io.socket.client.Socket;
import okhttp3.OkHttpClient;
import java.net.URISyntaxException;
public class ConnectionFailure {
public static void main(String[] args) throws URISyntaxException {
int port = 60_000;
IO.Options options = new IO.Options();
options.forceNew = true;
options.reconnection = false;
final OkHttpClient client = new OkHttpClient();
options.webSocketFactory = client;
options.callFactory = client;
final Socket socket = IO.socket("http://localhost:" + port, options);
socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println("connect error");
client.dispatcher().executorService().shutdown();
}
}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println("disconnect");
}
});
socket.open();
}
}