本文整理汇总了Java中io.github.sac.BasicListener类的典型用法代码示例。如果您正苦于以下问题:Java BasicListener类的具体用法?Java BasicListener怎么用?Java BasicListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicListener类属于io.github.sac包,在下文中一共展示了BasicListener类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import io.github.sac.BasicListener; //导入依赖的package包/类
public void start() {
if (socketThread == null) {
socketThread = new Thread(new Runnable() {
@Override
public void run() {
Socket socket = new Socket("ws://" + config.host + ":" + config.port + "/socketcluster/");
socket.setListener(new BasicListener() {
@Override
public void onConnected(Socket socket, Map<String, List<String>> headers) {
System.out.println("Connected");
}
@Override
public void onDisconnected(Socket socket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) {
System.out.println("Disconnected: " + closedByServer);
}
@Override
public void onConnectError(Socket socket, WebSocketException exception) {
exception.printStackTrace();
}
@Override
public void onAuthentication(Socket socket, Boolean status) {
}
@Override
public void onSetAuthToken(String token, Socket socket) {
}
});
socket.connect();
while (true) {
try {
Message<S, A> message = queue.take();
if (message == Message.END) {
socket.disconnect();
break;
}
JSONObject json = new JSONObject();
json.put("type", "ACTION");
JSONObject action = new JSONObject();
action.put("action", jsonify(message.action, true));
action.put("timestamp", new Date().getTime());
json.put("action", action);
json.put("payload", jsonify(message.state, false));
json.put("instanceId", store.getClass());
socket.emit("log-noid", json);
} catch (InterruptedException e) {
break;
} catch (JSONException e) {
break;
}
}
}
});
socketThread.start();
}
}