-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChatLauncher.java
42 lines (33 loc) · 1.37 KB
/
ChatLauncher.java
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
38
39
40
41
42
package com.corundumstudio.socketio.demo;
import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketConfig;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.Transport;
import com.corundumstudio.socketio.listener.DataListener;
public class ChatLauncher {
public static void main(String[] args) throws InterruptedException {
DataFileLoader dataFileLoader = DataFileLoader.getInstance();
dataFileLoader.load();
Configuration config = new Configuration();
config.setHostname("localhost");
config.setPort(8888);
config.setBossThreads(1);
config.setWorkerThreads(Runtime.getRuntime().availableProcessors());
config.setTransports(Transport.WEBSOCKET);
SocketConfig socketConfig = new SocketConfig();
socketConfig.setReuseAddress(true);
config.setSocketConfig(socketConfig);
final SocketIOServer server = new SocketIOServer(config);
server.addEventListener("chatevent", String.class, new DataListener<String>() {
@Override
public void onData(SocketIOClient client, String data, AckRequest ackRequest) {
client.sendEvent("chatevent", dataFileLoader.getData());
}
});
server.start();
Thread.sleep(Integer.MAX_VALUE);
server.stop();
}
}