本文整理匯總了Java中org.eclipse.jetty.websocket.api.WebSocketAdapter類的典型用法代碼示例。如果您正苦於以下問題:Java WebSocketAdapter類的具體用法?Java WebSocketAdapter怎麽用?Java WebSocketAdapter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WebSocketAdapter類屬於org.eclipse.jetty.websocket.api包,在下文中一共展示了WebSocketAdapter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: connect
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void connect() throws Exception {
final WebSocketClient client = new WebSocketClient();
client.start();
final WebSocketAdapter socket = new WebSocketAdapter() {
@Override
public void onWebSocketConnect(Session session) {
session.getRemote().sendStringByFuture("yo man!");
session.close();
}
};
client.connect(
socket,
URI.create("ws://localhost:8080/ws/"),
new ClientUpgradeRequest()
);
Thread.sleep(1000L);
client.stop();
}
示例2: testClose
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testClose() throws Throwable {
websocketAction(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.close();
}
});
client.connect(new WebSocketAdapter() {
@Override
public void onWebSocketClose(int statusCode, String reason) {
resume();
}
}, URI.create(uri()));
await();
}
示例3: testSendTextFrame
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testSendTextFrame() throws Throwable {
websocketAction(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.send("A Will Remains in the Ashes");
}
});
client.connect(new WebSocketAdapter() {
@Override
public void onWebSocketText(String message) {
threadAssertEquals(message, "A Will Remains in the Ashes");
resume();
}
}, URI.create(uri()));
await();
}
示例4: testSendBinaryFrame
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testSendBinaryFrame() throws Throwable {
websocketAction(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.send(ByteBuffer.wrap(new byte[]{0x00, 0x01, 0x02}).asReadOnlyBuffer());
}
});
client.connect(new WebSocketAdapter() {
@Override
public void onWebSocketBinary(byte[] payload, int offset, int len) {
threadAssertTrue(Arrays.equals(payload, new byte[]{0x00, 0x01, 0x02}));
resume();
}
}, URI.create(uri()));
await();
}
示例5: testOntext
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testOntext() throws Throwable {
websocketAction(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.ontext(new Action<String>() {
@Override
public void on(String data) {
threadAssertEquals(data, "A road of winds the water builds");
resume();
}
});
}
});
client.connect(new WebSocketAdapter() {
@Override
public void onWebSocketConnect(Session session) {
session.getRemote().sendString("A road of winds the water builds", ASYNC);
}
}, URI.create(uri()));
await();
}
示例6: testOnbinary
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testOnbinary() throws Throwable {
websocketAction(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.onbinary(new Action<ByteBuffer>() {
@Override
public void on(ByteBuffer data) {
threadAssertEquals(data, ByteBuffer.wrap(new byte[]{0x00, 0x01, 0x02}));
resume();
}
});
}
});
client.connect(new WebSocketAdapter() {
@Override
public void onWebSocketConnect(Session session) {
session.getRemote().sendBytes(ByteBuffer.wrap(new byte[]{0x00, 0x01, 0x02}), ASYNC);
}
}, URI.create(uri()));
await();
}
示例7: testOncloseByClient
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testOncloseByClient() throws Throwable {
websocketAction(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.onclose(new VoidAction() {
@Override
public void on() {
resume();
}
});
}
});
client.connect(new WebSocketAdapter() {
@Override
public void onWebSocketConnect(Session session) {
session.close();
}
}, URI.create(uri()));
await();
}
示例8: close
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void close() {
performer.clientListener(new WebSocketAdapter() {
@Override
public void onWebSocketClose(int statusCode, String reason) {
performer.start();
}
})
.onserver(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.close();
}
})
.connect();
}
示例9: close_idempotent
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void close_idempotent() {
performer.clientListener(new WebSocketAdapter() {
@Override
public void onWebSocketClose(int statusCode, String reason) {
performer.start();
}
})
.onserver(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.close();
ws.close();
}
})
.connect();
}
示例10: send_text
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void send_text() {
performer.clientListener(new WebSocketAdapter() {
@Override
public void onWebSocketText(String message) {
assertThat(message, is("A Will Remains in the Ashes"));
performer.start();
}
})
.onserver(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.send("A Will Remains in the Ashes");
}
})
.connect();
}
示例11: send_binary
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void send_binary() {
performer.clientListener(new WebSocketAdapter() {
@Override
public void onWebSocketBinary(byte[] payload, int offset, int len) {
assertThat(payload, is(new byte[] { 0x00, 0x01, 0x02 }));
performer.start();
}
})
.onserver(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.send(ByteBuffer.wrap(new byte[] { 0x00, 0x01, 0x02 }).asReadOnlyBuffer());
}
})
.connect();
}
示例12: onclose_by_client
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void onclose_by_client() {
performer.clientListener(new WebSocketAdapter() {
@Override
public void onWebSocketConnect(Session sess) {
sess.close();
}
})
.onserver(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
ws.onclose(new VoidAction() {
@Override
public void on() {
performer.start();
}
});
}
})
.connect();
}
示例13: onMessage
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Override
public void onMessage(WebSocketAdapter client, String message) {
try {
onMessage((HarAdapter) client, (JSONObject) JSONValue.parse(message));
} catch (Exception ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
}
示例14: unwrap
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void unwrap() throws Throwable {
websocketAction(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
threadAssertTrue(ws.unwrap(ChannelHandlerContext.class) instanceof ChannelHandlerContext);
threadAssertTrue(ws.unwrap(WebSocketServerHandshaker.class) instanceof
WebSocketServerHandshaker);
threadAssertTrue(ws.unwrap(FullHttpRequest.class) instanceof FullHttpRequest);
resume();
}
});
client.connect(new WebSocketAdapter(), URI.create(uri()));
await();
}
示例15: unwrap
import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void unwrap() throws Throwable {
websocketAction(new Action<ServerWebSocket>() {
@Override
public void on(ServerWebSocket ws) {
threadAssertTrue(ws.unwrap(org.vertx.java.core.http.ServerWebSocket.class) instanceof org
.vertx.java.core.http.ServerWebSocket);
resume();
}
});
client.connect(new WebSocketAdapter(), URI.create(uri()));
await();
}