0
回答
Netty发送请求,设置websocketPath路径
百度AI开发者大赛带你边学边开发,赢100万奖金,加群:418589053   

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());

    }
}

 

举报
mmdee
发帖于5天前 0回/32阅
顶部