当前位置: 首页>>代码示例>>Java>>正文


Java TextWebSocketFrame类代码示例

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


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

示例1: send

import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入依赖的package包/类
/**
 * Sends this response to all the passed channels as a {@link TextWebSocketFrame}
 * @param listener A channel future listener to attach to each channel future. Ignored if null.
 * @param channels The channels to send this response to
 * @return An array of the futures for the write of this response to each channel written to
 */
public ChannelFuture[] send(ChannelFutureListener listener, Channel...channels) {
	if(channels!=null && channels.length>0) {
		Set<ChannelFuture> futures = new HashSet<ChannelFuture>(channels.length);
		if(opCode==null) {
			opCode = "ok";
		}
		TextWebSocketFrame frame = new TextWebSocketFrame(this.toChannelBuffer());
		for(Channel channel: channels) {
			if(channel!=null && channel.isWritable()) {
				ChannelFuture cf = Channels.future(channel);
				if(listener!=null) cf.addListener(listener);
				channel.getPipeline().sendDownstream(new DownstreamMessageEvent(channel, cf, frame, channel.getRemoteAddress()));
				futures.add(cf);
			}
		}
		return futures.toArray(new ChannelFuture[futures.size()]);
	}		
	return EMPTY_CHANNEL_FUTURE_ARR;
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:26,代码来源:Netty3JSONResponse.java

示例2: sendMessage

import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入依赖的package包/类
private boolean sendMessage(String path, Object message, Channel channel) {
	if (channel.isConnected() && (channel instanceof ChannelWrapper)) {
		ChannelWrapper channelWrapper = (ChannelWrapper) channel;

		if (path.equals(channelWrapper.path)) {
			String msg = null;

			if (message != null) {
				try {
					msg = (message instanceof String) ? (String) message : MAPPER.writeValueAsString(message);
				} catch (JsonProcessingException ignored) {
				}
			}

			channel.write(new TextWebSocketFrame(msg));
			return true;
		}
	}

	return false;
}
 
开发者ID:iceize,项目名称:netty-http-3.x,代码行数:22,代码来源:WebSocketDispatcher.java

示例3: decode

import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入依赖的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

示例4: handleDownstream

import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入依赖的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

示例5: handleWebSocketFrame

import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入依赖的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

示例6: handleRequest

import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入依赖的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

示例7: send

import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入依赖的package包/类
public void send(String mes) {
    if (this.channel.isWritable()) {
        this.channel.write(new TextWebSocketFrame(mes));
    }
}
 
开发者ID:hou80houzhu,项目名称:rocserver,代码行数:6,代码来源:Connect.java

示例8: send

import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; //导入依赖的package包/类
public void send(String message) {
    this.ch.write(new TextWebSocketFrame(message));
}
 
开发者ID:Lightstreamer,项目名称:Lightstreamer-toolkit-socket.io-benchmark,代码行数:4,代码来源:WebSocketConnection.java


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