本文整理匯總了Java中io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame類的典型用法代碼示例。如果您正苦於以下問題:Java BinaryWebSocketFrame類的具體用法?Java BinaryWebSocketFrame怎麽用?Java BinaryWebSocketFrame使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BinaryWebSocketFrame類屬於io.netty.handler.codec.http.websocketx包,在下文中一共展示了BinaryWebSocketFrame類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: performSend
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
private void performSend(byte[] raw) throws IOException
{
if (this.outBuf != null)
{
this.outBuf.write(raw);
raw = this.outBuf.toByteArray();
this.outBuf = null;
}
//char[] encoded = Base64.encode(raw);
if (this.binary)
{
this.ctx.channel().write(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(raw)));
}
else
{
this.ctx.channel().write(new TextWebSocketFrame(StringUtil.toUtfString(raw)));
}
}
示例2: handleWebSocketFrame
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format(
"Channel %s received %s", ctx.channel().hashCode(), StringUtil.simpleClassName(frame)));
}
if (frame instanceof CloseWebSocketFrame) {
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
} else if (frame instanceof PingWebSocketFrame) {
ctx.write(new PongWebSocketFrame(frame.isFinalFragment(), frame.rsv(), frame.content()), ctx.voidPromise());
} else if (frame instanceof TextWebSocketFrame) {
ctx.write(frame, ctx.voidPromise());
} else if (frame instanceof BinaryWebSocketFrame) {
ctx.write(frame, ctx.voidPromise());
} else if (frame instanceof ContinuationWebSocketFrame) {
ctx.write(frame, ctx.voidPromise());
} else if (frame instanceof PongWebSocketFrame) {
frame.release();
// Ignore
} else {
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
.getName()));
}
}
示例3: channelRead0
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) {
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
System.out.println("WebSocket Client UID:[" + this.uid + "] handshaker connected!");
handshakeFuture.setSuccess();
return;
}
if (msg instanceof BinaryWebSocketFrame) {
try {
Object obj = protobufDecoder.decode(((BinaryWebSocketFrame) msg).content());
resQueue.add((Response.HeshResMessage)obj);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例4: encode
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, Proto proto, List<Object> list) throws Exception {
ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer();
if (proto.getBody() != null) {
byteBuf.writeInt(Proto.HEADER_LENGTH + proto.getBody().length);
byteBuf.writeShort(Proto.HEADER_LENGTH);
byteBuf.writeShort(Proto.VERSION);
byteBuf.writeInt(proto.getOperation());
byteBuf.writeInt(proto.getSeqId());
byteBuf.writeBytes(proto.getBody());
} else {
byteBuf.writeInt(Proto.HEADER_LENGTH);
byteBuf.writeShort(Proto.HEADER_LENGTH);
byteBuf.writeShort(Proto.VERSION);
byteBuf.writeInt(proto.getOperation());
byteBuf.writeInt(proto.getSeqId());
}
list.add(new BinaryWebSocketFrame(byteBuf));
logger.debug("encode: {}", proto);
}
示例5: testVersion
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
@Test
public void testVersion() throws Exception {
try {
String uuid = UUID.randomUUID().toString();
VersionRequest request = new VersionRequest();
request.setRequestId(uuid);
ch.writeAndFlush(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(JsonSerializer.getObjectMapper()
.writeValueAsBytes(request))));
// Confirm receipt of all data sent to this point
List<byte[]> response = handler.getResponses();
while (response.size() == 0 && handler.isConnected()) {
LOG.info("Waiting for web socket response");
sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
response = handler.getResponses();
}
assertEquals(1, response.size());
VersionResponse version = JsonSerializer.getObjectMapper()
.readValue(response.get(0), VersionResponse.class);
assertEquals(VersionResponse.VERSION, version.getVersion());
assertEquals(uuid, version.getRequestId());
} finally {
ch.close().sync();
s.shutdown();
group.shutdownGracefully();
}
}
示例6: encode
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void encode(ChannelHandlerContext ctx, Packet packet, List out) throws Exception {
ByteBuf buf = ctx.alloc().buffer().order(ByteOrder.LITTLE_ENDIAN);
int packetId = PacketRegistry.SERVER2CLIENT.getPacketId(packet.getClass());
if (packetId == -1) {
throw new IllegalArgumentException("Provided packet is not registered as a clientbound packet!");
}
buf.writeByte(packetId);
packet.writeData(buf);
new BinaryWebSocketFrame(buf);
out.add(new BinaryWebSocketFrame(buf));
Log.logDebug("Sent packet ID " + packetId + " (" + packet.getClass().getSimpleName() + ") to " + ctx.channel().remoteAddress());
}
示例7: handleFrame
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
private void handleFrame(Channel channel, WebSocketFrame frame, WebSocketUpgradeHandler handler, NettyWebSocket webSocket) throws Exception {
if (frame instanceof CloseWebSocketFrame) {
Channels.setDiscard(channel);
CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame;
webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText());
} else {
ByteBuf buf = frame.content();
if (buf != null && buf.readableBytes() > 0) {
HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, frame.isFinalFragment());
handler.onBodyPartReceived(part);
if (frame instanceof BinaryWebSocketFrame) {
webSocket.onBinaryFragment(part);
} else if (frame instanceof TextWebSocketFrame) {
webSocket.onTextFragment(part);
} else if (frame instanceof PingWebSocketFrame) {
webSocket.onPing(part);
} else if (frame instanceof PongWebSocketFrame) {
webSocket.onPong(part);
}
}
}
}
示例8: decodeWebSocketFrame
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
private Message decodeWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
// Check for closing frame
if (frame instanceof CloseWebSocketFrame) {
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
return null;
}
if (frame instanceof PingWebSocketFrame) {
ctx.write(new PongWebSocketFrame(frame.content().retain()));
return null;
}
if (frame instanceof TextWebSocketFrame) {
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
return parseMessage(textFrame.content());
}
if (frame instanceof BinaryWebSocketFrame) {
BinaryWebSocketFrame binFrame = (BinaryWebSocketFrame) frame;
return parseMessage(binFrame.content());
}
log.warn("Message format error: " + frame);
return null;
}
示例9: handleWebSocketFrame
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
// Check for closing frame
if (frame instanceof CloseWebSocketFrame) {
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
return;
}
if (frame instanceof PingWebSocketFrame) {
ctx.write(new PongWebSocketFrame(frame.content().retain()));
return;
}
if (frame instanceof TextWebSocketFrame) {
// Echo the frame
ctx.write(frame.retain());
return;
}
if (frame instanceof BinaryWebSocketFrame) {
// Echo the frame
ctx.write(frame.retain());
return;
}
}
示例10: channelRead0
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println("client channelRead0 "+ctx);
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
System.out.println("WebSocket Client connected!");
handshakeFuture.setSuccess();
}
if(msg instanceof WebSocketFrame){
WebSocketFrame frame = (WebSocketFrame)msg;
if(frame instanceof BinaryWebSocketFrame){
handleWebSocketFrame(ctx, frame);
}
return;
}
return;
}
示例11: channelRead0
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println("client channelRead0 "+ctx);
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
System.out.println("WebSocket Client connected!");
handshakeFuture.setSuccess();
}
if(msg instanceof WebSocketFrame){
WebSocketFrame frame = (WebSocketFrame)msg;
if(frame instanceof BinaryWebSocketFrame){
handleWebSocketFrame(ctx, frame);
}
return;
}
sendRealTimeMessageTest(ctx);
return;
}
示例12: channelRead0
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext context, Object message) throws Exception {
final Channel channel = context.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(channel, (FullHttpResponse) message);
channel.pipeline().addBefore(HANDLER_NAME, "websocket-frame-aggregator", new WebSocketFrameAggregator(64 * 1024));
subscriber.onStart();
return;
}
if (message instanceof FullHttpResponse) {
final FullHttpResponse response = (FullHttpResponse) message;
throw new IllegalStateException(
"Unexpected FullHttpResponse (getStatus=" + response.getStatus() +
", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
}
final WebSocketFrame frame = (WebSocketFrame) message;
if (frame instanceof PingWebSocketFrame) {
context.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame)frame).retain().content()));
} else if (frame instanceof BinaryWebSocketFrame) {
final ByteBufInputStream input = new ByteBufInputStream(((BinaryWebSocketFrame)message).content());
final Envelope envelope = Envelope.ADAPTER.decode(input);
subscriber.onNext(envelope);
}
}
示例13: ReactiveSocketWebSocketClient
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
private ReactiveSocketWebSocketClient(WebSocketConnection wsConn) {
this.reactiveSocket = ReactiveSocket.createRequestor();
connect = this.reactiveSocket.connect(
new DuplexConnection() {
@Override
public Publisher<Frame> getInput() {
return toPublisher(wsConn.getInput().map(frame -> {
return Frame.from(frame.content().nioBuffer());
}));
}
@Override
public Publisher<Void> addOutput(Publisher<Frame> o) {
// had to use writeAndFlushOnEach instead of write for frames to get through
// TODO determine if that's expected or not
Publisher<Void> p = toPublisher(wsConn.writeAndFlushOnEach(toObservable(o)
.map(frame -> new BinaryWebSocketFrame(Unpooled.wrappedBuffer(frame.getByteBuffer())))
));
return p;
}
});
}
開發者ID:NiteshKant,項目名稱:reactivesocket-websocket-rxnetty,代碼行數:23,代碼來源:ReactiveSocketWebSocketClient.java
示例14: acceptWebsocket
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
/**
* Use this method as the RxNetty HttpServer WebSocket handler.
*
* @param ws
* @return
*/
public Observable<Void> acceptWebsocket(WebSocketConnection ws) {
return toObservable(reactiveSocket.connect(new DuplexConnection() {
@Override
public Publisher<Frame> getInput() {
return toPublisher(ws.getInput().map(frame -> {
// TODO is this copying bytes?
try {
return Frame.from(frame.content().nioBuffer());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}));
}
@Override
public Publisher<Void> addOutput(Publisher<Frame> o) {
// had to use writeAndFlushOnEach instead of write for frames to reliably get through
// TODO determine if that's expected or not
return toPublisher(ws.writeAndFlushOnEach(toObservable(o).map(frame -> {
return new BinaryWebSocketFrame(Unpooled.wrappedBuffer(frame.getByteBuffer()));
})));
}
}));
}
開發者ID:NiteshKant,項目名稱:reactivesocket-websocket-rxnetty,代碼行數:32,代碼來源:ReactiveSocketWebSocketServer.java
示例15: channelRead0
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; //導入依賴的package包/類
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
handshakeFuture.setSuccess();
return;
}
if (!(msg instanceof BinaryWebSocketFrame)) {
ch.close();
log.warn("Received {}, closing", msg);
return;
}
byte[] b = extractBytes(msg);
ctx.fireChannelRead(b);
}