-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathConnectionFailure.java
More file actions
34 lines (29 loc) · 1.09 KB
/
Copy pathConnectionFailure.java
File metadata and controls
34 lines (29 loc) · 1.09 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
package io.socket.engineio.client.executions;
import io.socket.emitter.Emitter;
import io.socket.engineio.client.Socket;
import okhttp3.OkHttpClient;
import java.net.URISyntaxException;
public class ConnectionFailure {
public static void main(String[] args) throws URISyntaxException {
final OkHttpClient client = new OkHttpClient();
Socket.Options opts = new Socket.Options();
opts.webSocketFactory = client;
opts.callFactory = client;
int port = Integer.parseInt(System.getenv("PORT"));
port++;
final Socket socket = new Socket("http://localhost:" + port, opts);
socket.on(Socket.EVENT_CLOSE, new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println("close");
}
}).on(Socket.EVENT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println("error");
client.dispatcher().executorService().shutdown();
}
});
socket.open();
}
}