• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WebSocketFrame类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame的典型用法代码示例。如果您正苦于以下问题:Java WebSocketFrame类的具体用法?Java WebSocketFrame怎么用?Java WebSocketFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WebSocketFrame类属于org.jboss.netty.handler.codec.http.websocketx包,在下文中一共展示了WebSocketFrame类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handleWebSocketFrame

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
private void handleWebSocketFrame(final ChannelHandlerContext ctx, WebSocketFrame frame)
        throws Exception {
    if (frame instanceof CloseWebSocketFrame) {
        this.logger.info(Text.WS_CONNECTION_CLOSED_BY,
                ((CloseWebSocketFrame) frame).getStatusCode(),
                this.closedReason = ((CloseWebSocketFrame) frame).getReasonText());
        ctx.getChannel().close();
        return;
    } else if (frame instanceof BinaryWebSocketFrame) {
        if (!((BinaryWebSocketFrame) frame).isFinalFragment()) {
            this.logger.warn(Text.WS_NOT_FINAL);
            return;
        }
        if (this.channelHandler != null) {
            // if not final frame,
            // should wait until final frame received
            // https://github.com/wsky/top-link/issues/5
            ChannelBuffer buffer = ((BinaryWebSocketFrame) frame).getBinaryData();
            this.channelHandler.onMessage(this.createContext(buffer.toByteBuffer()));
        }
    }
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("unhandled frame: %s", frame);
    }
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:26,代码来源:WebSocketServerUpstreamHandler.java


示例2: decode

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer,
        State state) throws Exception {
    Object o = super.decode(ctx, channel, buffer, state);

    if (o == null) {
        return null;
    }

    if (!((o instanceof BinaryWebSocketFrame) || (o instanceof TextWebSocketFrame))) {
        return o;
    }

    // collect binary/text frame only
    this.cumulation.add((WebSocketFrame) o);
    // always return null making calldecode break and do not raise
    // unfoldAndFireMessageReceived
    return null;
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:20,代码来源:CustomWebSocket13FrameDecoder.java


示例3: handleWebSocketFrame

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame)
        throws Exception {
    if (frame instanceof CloseWebSocketFrame) {
        this.logger.info(Text.WS_CONNECTION_CLOSED_BY,
                ((CloseWebSocketFrame) frame).getStatusCode(),
                this.closedReason = ((CloseWebSocketFrame) frame).getReasonText());
        CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame;
        this.clear(ctx);
        this.logger.warn(Text.WS_CONNECTION_CLOSED_BY, closeFrame.getStatusCode(),
                closeFrame.getReasonText());
    } else if (frame instanceof BinaryWebSocketFrame) {
        if (!((BinaryWebSocketFrame) frame).isFinalFragment()) {
            this.logger.warn(Text.WS_NOT_FINAL);
            return;
        }
        if (this.haveHandler()) {
            ChannelBuffer buffer = ((BinaryWebSocketFrame) frame).getBinaryData();
            this.getHandler().onMessage(this.createContext(buffer.toByteBuffer()));
        }
    }
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:22,代码来源:WebSocketClientUpstreamHandler.java


示例4: frameReceived

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
@Override
public void frameReceived(WebSocketFrame msg) {

	if (socketChannel != null) {
		if (socketChannel.isConnected()) {
			if (log.isDebugEnabled()) {
				log.debug("Forwarding frame to socket "
						+ socketChannel.getRemoteAddress());
			}

			reportInputBytes(msg.getBinaryData()
					.readableBytes());
			socketChannel.write(msg.getBinaryData());
		} else {
			if (log.isDebugEnabled()) {
				log.debug("Forwarding socket is no longer connected for "
						+ socketChannel.getRemoteAddress());
			}
			close();
		}
	}

	
}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:25,代码来源:SocketForwardingWebsocketClient.java


示例5: processWebsocketFrame

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
private void processWebsocketFrame(WebSocketFrame msg, Channel channel) {

		if (log.isDebugEnabled()) {
			log.debug("Received websocket frame from "
					+ channel.getRemoteAddress());
		}
		// Check for closing frame
		if (msg instanceof CloseWebSocketFrame) {
			// handshaker.close(channel, (CloseWebSocketFrame) msg);
			return;
		} else if (!(msg instanceof BinaryWebSocketFrame)) {
			// Close
		}

		NettyWebsocketClient nettyClient = (NettyWebsocketClient) channel.getAttachment();
		nettyClient.frameReceived(msg);
		
	}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:19,代码来源:HttpRequestDispatcherHandler.java


示例6: handleDownstream

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.jboss.netty.channel.ChannelDownstreamHandler#handleDownstream(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelEvent)
 */
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
	Channel channel = e.getChannel();
	if(!channel.isOpen()) return;
	if(!(e instanceof MessageEvent)) {
           ctx.sendDownstream(e);
           return;
       }
	Object message = ((MessageEvent)e).getMessage();
	if((message instanceof HttpResponse) || (message instanceof WebSocketFrame)) {
		ctx.sendDownstream(e);
		return;
	}
	if((message instanceof ChannelBuffer)) {
		ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame((ChannelBuffer)message), channel.getRemoteAddress()));
	} else if((message instanceof JsonNode)) {  			
		String json = marshaller.writeValueAsString(message);
		ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(json), channel.getRemoteAddress()));			
	} else if((message instanceof ChannelBufferizable)) {
		ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(((Netty3ChannelBufferizable)message).toChannelBuffer()), channel.getRemoteAddress()));
	} else if((message instanceof CharSequence)) {
		ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(marshaller.writeValueAsString(message)), channel.getRemoteAddress()));
	} else if((message instanceof JSONResponse)) {				
		ObjectMapper mapper = (ObjectMapper)((JSONResponse)message).getChannelOption("mapper", TSDBTypeSerializer.DEFAULT.getMapper());			
		ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(mapper.writeValueAsString(message)), channel.getRemoteAddress()));					
	} else {
           ctx.sendUpstream(e);
	}		
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:34,代码来源:WebSocketServiceHandler.java


示例7: handleUpstream

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.jboss.netty.channel.ChannelUpstreamHandler#handleUpstream(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelEvent)
 */
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
	log.warn("ChannelEvent: {}", e);
	if(e instanceof MessageEvent) {
		Object message = ((MessageEvent)e).getMessage();
		if (message instanceof HttpRequest) {
			handleRequest(ctx, (HttpRequest) message, (MessageEvent)e);
		} else if (message instanceof WebSocketFrame) {
			handleRequest(ctx, (WebSocketFrame) message);
		}
	} else {
		ctx.sendUpstream(e);
	}			
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:19,代码来源:WebSocketServiceHandler.java


示例8: send

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
private boolean send(WebSocketFrame frame, final SendHandler sendHandler, int timeout)
        throws ChannelException {
    // do not support fragmentation
    frame.setFinalFragment(true);

    // weather sendSync enabled
    final CountDownLatch latch = timeout > 0 ? new CountDownLatch(1) : null;

    this.channel.write(frame).addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (latch != null) {
                latch.countDown();
            } else if (sendHandler != null) {
                sendHandler.onSendComplete(future.isSuccess());
            }
        }
    });

    if (latch == null) {
        return true;
    }

    // boolean success = false;
    try {
        return latch.await(timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        throw new ChannelException(Text.WS_SEND_SYNC_ERROR, e);
    } finally {
        // not safe, timeout message already in netty sendbuffer and will be
        // sent later,
        // if buffer clear in onSendComplete, client will got wrong message
        // if (sendHandler != null)
        // sendHandler.onSendComplete(success);
    }
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:38,代码来源:WebSocketChannelSender.java


示例9: messageReceived

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    Object msg = e.getMessage();
    if (msg instanceof HttpRequest) {
        this.handleHttpRequest(ctx, (HttpRequest) msg);
    } else if (msg instanceof WebSocketFrame) {
        this.handleWebSocketFrame(ctx, (WebSocketFrame) msg);
    } else if (msg instanceof List<?>) {
        this.handleWebSocketFrame(ctx, (List<WebSocketFrame>) msg);
    }
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:13,代码来源:WebSocketServerUpstreamHandler.java


示例10: messageReceived

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    this.cumulation = new ArrayList<WebSocketFrame>();
    super.messageReceived(ctx, e);
    // batch FireMessageReceived
    if (this.cumulation.size() > 0) {
        Channels.fireMessageReceived(ctx, cumulation, e.getRemoteAddress());
    }
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:10,代码来源:CustomWebSocket13FrameDecoder.java


示例11: messageReceived

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    if (!this.handshaker.isHandshakeComplete()) {
        this.handleHandshake(ctx, (HttpResponse) e.getMessage());
    }
    if (e.getMessage() instanceof WebSocketFrame) {
        this.handleWebSocketFrame(ctx, (WebSocketFrame) e.getMessage());
    }
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:10,代码来源:WebSocketClientUpstreamHandler.java


示例12: messageReceived

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
{
	Object msg = e.getMessage();
	if (msg instanceof HttpRequest)
	{
		this.handleHttpRequest(ctx, (HttpRequest) msg);
	}
	else if (msg instanceof WebSocketFrame)
	{
		this.handleWebSocketFrame(ctx, (WebSocketFrame) msg);
	}
}
 
开发者ID:EricssonResearch,项目名称:trap,代码行数:14,代码来源:WebServerSocketHandler.java


示例13: messageReceived

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
{
	Channel ch = ctx.getChannel();
	if (!this.handshaker.isHandshakeComplete())
	{
		this.ch = ch;
		this.handshaker.finishHandshake(ch, (HttpResponse) e.getMessage());
		this.t.notifyOpen();
		return;
	}
	
	if (e.getMessage() instanceof HttpResponse)
	{
		HttpResponse response = (HttpResponse) e.getMessage();
		throw new Exception("Unexpected HttpResponse (status=" + response.getStatus() + ", content=" + response.getContent().toString(CharsetUtil.UTF_8) + ")");
	}
	
	WebSocketFrame frame = (WebSocketFrame) e.getMessage();
	if (frame instanceof BinaryWebSocketFrame)
	{
		BinaryWebSocketFrame f = (BinaryWebSocketFrame) frame;
		ChannelBuffer binaryData = f.getBinaryData();
		byte[] arr = new byte[binaryData.readableBytes()];
		binaryData.readBytes(arr);
		this.t.notifyMessage(arr);

	}
	else if (frame instanceof PongWebSocketFrame)
	{
		System.out.println("WebSocket Client received pong");
	}
	else if (frame instanceof CloseWebSocketFrame)
	{
		System.out.println("WebSocket Client received closing");
		ch.close();
	}
}
 
开发者ID:EricssonResearch,项目名称:trap,代码行数:39,代码来源:NettyWSClient.java


示例14: messageReceived

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    Object msg = e.getMessage();
    if (msg instanceof HttpRequest) {
        handleHttpRequest(ctx, (HttpRequest) msg);
    } else if (msg instanceof WebSocketFrame) {
        handleWebSocketFrame(ctx, (WebSocketFrame) msg);
    }
}
 
开发者ID:hou80houzhu,项目名称:rocserver,代码行数:10,代码来源:WebSocketServerHandler.java


示例15: handleWebSocketFrame

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
    Connect connect = connects.getConnect(ctx.getChannel().getId() + "");
    try {
        if (frame instanceof CloseWebSocketFrame) {
            handshaker.close(ctx.getChannel(), (CloseWebSocketFrame) frame);
        } else if (frame instanceof PingWebSocketFrame) {
            ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData()));
        } else if (frame instanceof TextWebSocketFrame) {
            String message = ((TextWebSocketFrame) frame).getText();
            Jsonx cc = Jsonx.create(message);
            SocketRequest request = cc.toObject(new SocketRequest());
            ObjectSnooper.snoop(request).set("session", connect.getSession());
            BaseSocketService service = SocketServiceMapping.getSocketServiceMapping().getService(cc.get("type").toString());
            service.setConnect(connect);
            service.setRequest(request);
            service.setConnections(connects);
            if (service != null) {
                service.doRoutResult();
            } else {
                throw new Exception("service can not support");
            }
        } else {
            throw new Exception("data error,");
        }
    } catch (Exception e) {
        e.printStackTrace();
        connect.send("{\"code\":0,\"mes\":" + e.getMessage() + "}");
    }
}
 
开发者ID:hou80houzhu,项目名称:rocserver,代码行数:30,代码来源:WebSocketServerHandler.java


示例16: messageReceived

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
		throws Exception {
	Object msg = e.getMessage();

	if(msg instanceof HttpRequest) {
	
		HttpRequest nettyRequest = (HttpRequest) msg;
		dispatchRequest(ctx, nettyRequest);

	} else if (msg instanceof WebSocketFrame) {

		processWebsocketFrame((WebSocketFrame) msg, ctx.getChannel());

	} else if (msg instanceof HttpChunk) {

		HttpChunk chunk = (HttpChunk) msg;
		
		if(log.isDebugEnabled()) {
			log.debug(String.format("Received HTTP chunk of %d bytes", ((HttpChunk) msg).getContent().readableBytes()));
		}
		
		HttpRequestServletWrapper servletRequest = (HttpRequestServletWrapper) ctx.getChannel().getAttachment();
		((HttpRequestChunkStream)servletRequest.getInputStream()).setCurrentChunk(chunk);

	} else {
		if (log.isErrorEnabled()) {
			log.error("Received invalid MessageEvent " + msg.toString());
		}
	}

}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:33,代码来源:HttpRequestDispatcherHandler.java


示例17: handleRequest

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
/**
	 * Processes a websocket request
	 * @param ctx The channel handler context
	 * @param frame The websocket frame request to process
	 */
	public void handleRequest(ChannelHandlerContext ctx, WebSocketFrame frame) {
        // Check for closing frame
        if (frame instanceof CloseWebSocketFrame) {
        	wsHandShaker.get(ctx.getChannel()).close(ctx.getChannel(), (CloseWebSocketFrame) frame);
            return;
        } else if (frame instanceof PingWebSocketFrame) {
            ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData()));
            return;
        } else if (!(frame instanceof TextWebSocketFrame)) {
            throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
                    .getName()));
        }
        String request = ((TextWebSocketFrame) frame).getText();
        Netty3JSONRequest wsRequest = null;
        try {
        	wsRequest = Netty3JSONRequest.newJSONRequest(ctx.getChannel(), request);
        	
//        	if("who".equals(wsRequest.getArgument("t").toString())) {
//        		SocketAddress sa = ctx.getChannel().getRemoteAddress();
//        		String host = "unknown";
//        		String agent = "unknown";
//        		if(sa!=null) {
//        			host = ((InetSocketAddress)sa).getHostName();        			
//        		}
//        		if(wsRequest.getArgument("agent")!=null) {
//        			agent = wsRequest.getArgument("agent").toString();
//        		}
//        		SharedChannelGroup.getInstance().add(ctx.getChannel(), ChannelType.WEBSOCKET_REMOTE, "ClientWebSocket", host, agent);
//        	} else {        		
        		router.route(wsRequest);
//        	}
        	
        		
        } catch (Exception ex) {
        	Netty3JSONResponse response = new Netty3JSONResponse(-1, ResponseType.ERR, ctx.getChannel(), wsRequest);
    		Map<String, String> map = new HashMap<String, String>(2);
    		map.put("err", "Failed to parse request [" + request + "]");
    		map.put("ex", StringHelper.formatStackTrace(ex));
    		response.setContent(map);
        	log.error("Failed to parse request [" + request + "]", ex);
        	ctx.getChannel().write(response);
        }		
	}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:49,代码来源:WebSocketServiceHandler.java


示例18: frameReceived

import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; //导入依赖的package包/类
void frameReceived(WebSocketFrame msg); 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:2,代码来源:NettyWebsocketClient.java



注:本文中的org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AutofitTextView类代码示例发布时间:2022-05-23
下一篇:
Java UnionFind类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap