org.bdware.client.ws.BaseClient Maven / Gradle / Ivy
package org.bdware.client.ws;
import java.io.IOException;
import javax.websocket.CloseReason;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.Session;
public class BaseClient extends Endpoint {
private Session session;
private boolean isConnected;
private WSHandler handler;
public BaseClient(Handler client) {
isConnected = false;
handler = new WSHandler(client);
}
@Override
public void onOpen(Session session, EndpointConfig config) {
this.session = session;
// session.getBasicRemote().sendText("Session ID: " + this.session.getId());
session.addMessageHandler(handler);
isConnected = true;
}
@Override
public void onClose(Session session, CloseReason config) {
this.session = null;
isConnected = false;
}
@Override
public void onError(Session session, Throwable config) {
this.session = null;
isConnected = false;
}
public void sendText(String text) {
try {
this.session.getBasicRemote().sendText(text);
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean connected() {
return isConnected;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy