Netty发送请求,设置websocketPath路径

发布于 2021-12-06 20:27:34 字数 1306 浏览 846 评论 2

Netty发送请求,设置websocketPath路径。服务器这是websocket路径是localhost:8080/ws。

这是服务端的配置,设置了请求路径是/ws

public class WebsocketChatServerInitializer extends
      ChannelInitializer<SocketChannel> {    //1

   @Override
    public void initChannel(SocketChannel ch) throws Exception {//2
       ChannelPipeline pipeline = ch.pipeline();

        pipeline.addLast(new HttpServerCodec());
      pipeline.addLast(new HttpObjectAggregator(64*1024));
      pipeline.addLast(new ChunkedWriteHandler());
      pipeline.addLast(new HttpRequestHandler("/ws"));
      pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
      pipeline.addLast(new TextWebSocketFrameHandler());

    }
}

我在客户端上怎么设置请求路径为/ws?

这是客户端的设置代码,不知道怎么设置请求路径

public class SimpleChatClientInitializer extends ChannelInitializer<SocketChannel> {
   @Override
    public void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        
        pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
        pipeline.addLast("decoder", new StringDecoder());
        pipeline.addLast("encoder", new StringEncoder());
        pipeline.addLast("handler", new SimpleChatClientHandler());

    }
}

 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫九 2021-12-08 05:19:47

兄弟你这个问题,怎么处理的呢

伴我心暖 2021-12-07 19:15:11

客户端直接用http或者前端 访问,不要再用netty

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文