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());
}
}
uj5u.com熱心網友回復:
我也是這個問題 ,沒想到這么多年過去了還是這個問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/267772.html
標籤:其他技術討論專區
上一篇:關閉sip無法打開ios應用問題
