use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class TestABCase2 method testCase2_10.
/**
* 10 pings
* @throws Exception on test failure
*/
@Test
public void testCase2_10() throws Exception {
// send 10 pings each with unique payload
// send close
// expect 10 pongs with our unique payload
// expect close
int pingCount = 10;
List<WebSocketFrame> send = new ArrayList<>();
List<WebSocketFrame> expect = new ArrayList<>();
for (int i = 0; i < pingCount; i++) {
String payload = String.format("ping-%d[%X]", i, i);
send.add(new PingFrame().setPayload(payload));
expect.add(new PongFrame().setPayload(payload));
}
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class TestABCase2 method testCase2_2.
/**
* Ping with small text payload
* @throws Exception on test failure
*/
@Test
public void testCase2_2() throws Exception {
byte[] payload = StringUtil.getUtf8Bytes("Hello world");
List<WebSocketFrame> send = new ArrayList<>();
send.add(new PingFrame().setPayload(payload));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new PongFrame().setPayload(copyOf(payload)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.PingFrame in project jetty.project by eclipse.
the class WebSocketFrame method copy.
public static WebSocketFrame copy(Frame original) {
WebSocketFrame copy;
switch(original.getOpCode()) {
case OpCode.BINARY:
copy = new BinaryFrame();
break;
case OpCode.TEXT:
copy = new TextFrame();
break;
case OpCode.CLOSE:
copy = new CloseFrame();
break;
case OpCode.CONTINUATION:
copy = new ContinuationFrame();
break;
case OpCode.PING:
copy = new PingFrame();
break;
case OpCode.PONG:
copy = new PongFrame();
break;
default:
throw new IllegalArgumentException("Cannot copy frame with opcode " + original.getOpCode() + " - " + original);
}
copy.copyHeaders(original);
ByteBuffer payload = original.getPayload();
if (payload != null) {
ByteBuffer payloadCopy = ByteBuffer.allocate(payload.remaining());
payloadCopy.put(payload.slice()).flip();
copy.setPayload(payloadCopy);
}
return copy;
}
Aggregations