netty往ios推送信息的问题

天王盖地虎626 发布于 2014/11/02 09:08
阅读 2K+
收藏 0

netty和ios进行信息推送,通过websocket,目前可以推送到苹果手机上了,但是查看服务端日志,总是报这个错误,另外,我用netty4.0.23版本,请求帮助

错误信息

 An exception was thrown by a user handler's exceptionCaught() method while handling the following exception:
io.netty.handler.codec.http.websocketx.WebSocketHandshakeException: not a WebSocket handshake request: missing upgrade

报错代码位置在标红处:

WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
                getWebSocketLocation(req), null, false);
        handshaker = wsFactory.newHandshaker(req);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
        } else {
             handshaker.handshake(ctx.channel(), req);
        }

 

加载中
0
天王盖地虎626
天王盖地虎626
没人回答问题呀
0
天王盖地虎626
天王盖地虎626
有人遇到过吗?请教下哦
0
c
catch23
握手我使用WebSocketServerProtocolHandler这个Handler处理的。
0
天王盖地虎626
天王盖地虎626

引用来自“catch23”的评论

握手我使用WebSocketServerProtocolHandler这个Handler处理的。
能发下你握手后怎么处理的呀,能发下代码吗?
0
c
catch23

引用来自“catch23”的评论

握手我使用WebSocketServerProtocolHandler这个Handler处理的。

引用来自“巴顿将军”的评论

能发下你握手后怎么处理的呀,能发下代码吗?
//init pipeline
ch.pipeline().addLast(new HttpServerCodec())
             .addLast(new HttpObjectAggregator(65535))
             .addLast(new WebSocketServerProtocolHandler("ws://127.0.0.1:8080/websocket"))
             .addLast(webSocketFrameInboundHandler)
public class WebSocketFrameInboundHandler extends ChannelInboundHandlerAdapter{

	private static Logger logger = LoggerFactory.getLogger(WebSocketFrameInboundHandler.class);

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		if(msg instanceof BinaryWebSocketFrame){
			BinaryWebSocketFrame bin = (BinaryWebSocketFrame)msg;
			ctx.fireChannelRead(bin.content());
		}else{
			ctx.fireChannelRead(msg);
		}
		
	}	
}


0
天王盖地虎626
天王盖地虎626

引用来自“catch23”的评论

握手我使用WebSocketServerProtocolHandler这个Handler处理的。

引用来自“巴顿将军”的评论

能发下你握手后怎么处理的呀,能发下代码吗?

引用来自“catch23”的评论

//init pipeline
ch.pipeline().addLast(new HttpServerCodec())
             .addLast(new HttpObjectAggregator(65535))
             .addLast(new WebSocketServerProtocolHandler("ws://127.0.0.1:8080/websocket"))
             .addLast(webSocketFrameInboundHandler)
public class WebSocketFrameInboundHandler extends ChannelInboundHandlerAdapter{

	private static Logger logger = LoggerFactory.getLogger(WebSocketFrameInboundHandler.class);

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		if(msg instanceof BinaryWebSocketFrame){
			BinaryWebSocketFrame bin = (BinaryWebSocketFrame)msg;
			ctx.fireChannelRead(bin.content());
		}else{
			ctx.fireChannelRead(msg);
		}
		
	}	
}


你的写法和我差不多呢,不知道怎么回事呢  

 @Override
    public void initChannel(SocketChannel ch) throws Exception {
       ChannelPipeline pipeline = ch.pipeline();
          if (sslCtx != null) {
              pipeline.addLast(sslCtx.newHandler(ch.alloc()));
          }
          pipeline.addLast(new HttpServerCodec());
          pipeline.addLast(new HttpObjectAggregator(65536));
         
          ////下面3行暂时放开
//          pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
//          pipeline.addLast("decoder", NettyConstants.DECODER);
//          pipeline.addLast("encoder", NettyConstants.ENCODER);
         
          ///设定超时时间
          pipeline.addLast("readTimeoutHandler",new ReadTimeoutHandler(NettyConstants.READTIMEOUT));
          pipeline.addLast("LoginAuthHandler",new LoginRespWebSocketServerHandler());
          pipeline.addLast("HeartBeatHandler",new HeartbeatRespWebSocketServerHandler());
         
//          pipeline.addLast("LoginAuthHandler",new LoginRespHandler());
//          pipeline.addLast("HeartBeatHandler",new HeartBeatRespHandler());
         // pipeline.addLast();
     
    }

 

 @Override
    public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
     
     //count=0;
     
        if (msg instanceof FullHttpRequest) {
            handleHttpRequest(ctx, (FullHttpRequest) msg);
        } else if (msg instanceof WebSocketFrame) {
            handleWebSocketFrame(ctx, (WebSocketFrame) msg);
        }
    }

 

0
K不是你的帝
K不是你的帝
兄弟,这个问题你最终解决了吗?去帮助
返回顶部
顶部