use of io.crossbar.autobahn.websocket.WebSocketConnectionHandler in project autobahn-java by crossbario.
the class EchoClientActivity method start.
private void start() {
String hostname = mHostname.getText().toString();
if (!hostname.startsWith("ws://") && !hostname.startsWith("wss://")) {
hostname = "ws://" + hostname;
}
String port = mPort.getText().toString();
String wsuri;
if (!port.isEmpty()) {
wsuri = hostname + ":" + port;
} else {
wsuri = hostname;
}
mStatusline.setText("Status: Connecting to " + wsuri + " ..");
setButtonDisconnect();
WebSocketOptions connectOptions = new WebSocketOptions();
connectOptions.setReconnectInterval(5000);
try {
mConnection.connect(wsuri, new WebSocketConnectionHandler() {
@Override
public void onOpen() {
mStatusline.setText("Status: Connected to " + wsuri);
savePrefs();
mSendMessage.setEnabled(true);
mMessage.setEnabled(true);
}
@Override
public void onMessage(String payload) {
alert("Got echo: " + payload);
}
@Override
public void onClose(int code, String reason) {
alert("Connection lost.");
mStatusline.setText("Status: Ready.");
setButtonConnect();
mSendMessage.setEnabled(false);
mMessage.setEnabled(false);
}
}, connectOptions);
} catch (WebSocketException e) {
Log.d(TAG, e.toString());
}
}
use of io.crossbar.autobahn.websocket.WebSocketConnectionHandler in project autobahn-java by crossbario.
the class TestSuiteClientActivity method queryCaseCount.
private void queryCaseCount() throws WebSocketException {
final WebSocketConnection webSocket = new WebSocketConnection();
webSocket.connect(mWsUri.getText() + "/getCaseCount", new WebSocketConnectionHandler() {
@Override
public void onOpen() {
savePrefs();
}
@Override
public void onMessage(String payload) {
lastCase = Integer.parseInt(payload);
}
@Override
public void onClose(int code, String reason) {
mStatusLine.setText("Ok, will run " + lastCase + " cases.");
currentCase += 1;
processNext();
}
});
}
use of io.crossbar.autobahn.websocket.WebSocketConnectionHandler in project autobahn-java by crossbario.
the class TestSuiteClientActivity method updateReport.
private void updateReport() throws WebSocketException {
WebSocketConnection webSocket = new WebSocketConnection();
webSocket.connect(mWsUri.getText() + "/updateReports?agent=" + mAgent.getText(), new WebSocketConnectionHandler() {
@Override
public void onOpen() {
mStatusLine.setText("Updating test reports ..");
}
@Override
public void onClose(int code, String reason) {
mStatusLine.setText("Test reports updated. Finished.");
mStart.setEnabled(true);
}
});
}
use of io.crossbar.autobahn.websocket.WebSocketConnectionHandler in project autobahn-java by crossbario.
the class TestSuiteClientActivity method runTest.
private void runTest() throws WebSocketException {
final WebSocketConnection webSocket = new WebSocketConnection();
webSocket.connect(mWsUri.getText() + "/runCase?case=" + currentCase + "&agent=" + mAgent.getText(), new WebSocketConnectionHandler() {
@Override
public void onMessage(String payload) {
webSocket.sendMessage(payload);
}
@Override
public void onMessage(byte[] payload, boolean isBinary) {
webSocket.sendMessage(payload, isBinary);
}
@Override
public void onOpen() {
updateText(mStatusLine, "Test case " + currentCase + "/" + lastCase + " started ..");
}
@Override
public void onClose(int code, String reason) {
mStatusLine.setText("Test case " + currentCase + "/" + lastCase + " finished.");
currentCase += 1;
processNext();
}
}, mOptions);
}
use of io.crossbar.autobahn.websocket.WebSocketConnectionHandler in project autobahn-java by crossbario.
the class AndroidWebSocket method connect.
@Override
public void connect(ITransportHandler transportHandler, TransportOptions options) throws Exception {
WebSocketOptions webSocketOptions = new WebSocketOptions();
webSocketOptions.setAutoPingInterval(options.getAutoPingInterval());
webSocketOptions.setAutoPingTimeout(options.getAutoPingTimeout());
webSocketOptions.setMaxFramePayloadSize(options.getMaxFramePayloadSize());
mConnection.connect(mUri, getSerializers(), new WebSocketConnectionHandler() {
@Override
public void onConnect(ConnectionResponse response) {
LOGGER.d(String.format("Negotiated serializer=%s", response.protocol));
try {
mSerializer = initializeSerializer(response.protocol);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onOpen() {
try {
transportHandler.onConnect(AndroidWebSocket.this, mSerializer);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onClose(int code, String reason) {
switch(code) {
case IWebSocketConnectionHandler.CLOSE_CONNECTION_LOST:
transportHandler.onLeave(new CloseDetails(CloseDetails.REASON_TRANSPORT_LOST, null));
break;
default:
transportHandler.onLeave(new CloseDetails(CloseDetails.REASON_DEFAULT, null));
}
LOGGER.d(String.format("Disconnected, code=%s, reasons=%s", code, reason));
transportHandler.onDisconnect(code == 1000);
}
@Override
public void onMessage(String payload) {
try {
transportHandler.onMessage(payload.getBytes(), false);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onMessage(byte[] payload, boolean isBinary) {
try {
transportHandler.onMessage(payload, isBinary);
} catch (Exception e) {
e.printStackTrace();
}
}
}, webSocketOptions, null);
}
Aggregations