Comments (6)
If you want to work only with Netty abstraction then you need some changes:
- Ensure that you can see the uncompressed data. Change the code
.doOnChannelInit(((connectionObserver, channel, remoteAddress) -> {
channel.pipeline()
.addFirst("connect", new ChannelHandler(this.manager));
}))
with moving the handler at the end
.doOnChannelInit(((connectionObserver, channel, remoteAddress) -> {
Connection.from(channel)
.addHandlerLast("connect", new ChannelHandler());
}))
- Work with Netty web socket API. Change the code
public class ChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
@Override
protected void channelRead0(@NotNull ChannelHandlerContext ctx, @NotNull ByteBuf msg) throws Exception {
System.out.println(msg.toString(StandardCharsets.UTF_8));
ctx.fireChannelRead(msg.copy());
}
}
with handler that manipulates web socket frames
public class ChannelHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
@Override
protected void channelRead0(@NotNull ChannelHandlerContext ctx, @NotNull WebSocketFrame msg) throws Exception {
System.out.println(msg.content().toString(StandardCharsets.UTF_8));
ctx.fireChannelRead(msg.copy());
}
}
I'm closing this issue as it feels like this is a question that would be better suited to Gitter or Stack Overflow.
from reactor-netty.
@AdaMorgan Most probably in the logs you are seeing the compressed content. From the provided logs I can see that the client sends Sec-WebSocket-Extensions: permessage-deflate
. Please provide a full reproducible example that we can run and see the problem.
from reactor-netty.
ok, I hope this is enough. Next, I create a connection via Postman. I have attached the result.
public class ChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
@Override
protected void channelRead0(@NotNull ChannelHandlerContext ctx, @NotNull ByteBuf msg) throws Exception {
System.out.println(msg.toString(StandardCharsets.UTF_8));
ctx.fireChannelRead(msg.copy());
}
}
public class Main {
public static void main (String[] args) {
public void run() {
HttpServer.create()
.host(this.config.getHost())
.port(this.config.getPort())
.protocol(HttpProtocol.HTTP11)
.doOnChannelInit(((connectionObserver, channel, remoteAddress) -> {
channel.pipeline()
.addFirst("connect", new ChannelHandler(this.manager));
}))
.route(routes -> routes.ws("/chat", (in, out) -> {
return in.receive()
.publishOn(Schedulers.boundedElastic())
.flatMap(socket -> {
return out.send(Mono.fromCallable(() -> {
return Unpooled.copiedBuffer("Hello client!", StandardCharsets.UTF_8);
}));
});
}))
.bindUntilJavaShutdown(Duration.ofSeconds(30), null);
}
}
}
GET /chat HTTP/1.1
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: R/9dk94SqnkDP5aXBFabLQ==
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Host: localhost:8080
?E��?�3-?_fy?Qa/?�1G?V}-?[tl?�? ?�3-?�~h?Mrj?�)-?vz!?�wl?���?
from reactor-netty.
@AdaMorgan You are adding the custom ChannelHandler at the beginning of the pipeline where you are still having a compressed data. Instead of this handler you can change, for example, the code above to this one:
...
return in.receive()
--> decodes ByteBuf to String .asString()
--> prints to System.out .doOnNext(System.out::println)
.publishOn(Schedulers.boundedElastic())
...
from reactor-netty.
I just can’t read the data through the ChannelHandler? I know that it would be possible to read the data through the 'WebsocketInbound' class, but I was hoping that I would not have to do it this way, since it increases the size of the project, and reading through the 'SimpleChannelInboundHandler' is much more difficult for me easier
from reactor-netty.
@violetagg Thank you very much, you helped a lot!
from reactor-netty.
Related Issues (20)
- Unable to configure Websocket compression when both HttpProtocol.H2C and HttpProtocol.HTTP1.1 are configured HOT 2
- Is it possible to be able to add custom labels to the metrics already being emitted HOT 2
- Regression from SpringBoot 3.2.2 Factory method 'webClientHttpConnector' threw exception with message: Cannot reserve 49152 bytes of direct buffer memory (allocated: 10452747, limit: 10485760) HOT 8
- out of memory when prometheus is enabled and url with path varaible HOT 5
- Enabling DNS retryOnTimeout with TCP HOT 2
- Inconsistent reactor_netty_http_client_* and reactor_netty_tcp_client_* metrics when proxy in use HOT 6
- Connections warming up HOT 4
- default port based on PORT environment variable HOT 1
- Graceful shutdown of HttpClient HOT 6
- Reactor Netty IllegalReferenceCountException: refCnt: 0 HOT 11
- Support For Spnego Auth scheme support for netty HttpClient similar to Apache's HOT 3
- HTTP/1.1 is being logged and recorded by metrics even though HTTP/2 is enabled HOT 10
- proxy-authorization header is not propagated to proxy server HOT 9
- Support for Spengo auth scheme support for netty HttpClient similar to Apache HttpClient HOT 2
- Spring Cloud Gateway use reactor netty :Response header and response body packet capture were found to be separate HOT 1
- CompletableFuture is cancelled because Netty is closing the connection channel HOT 5
- WebSockets - MaxFramePayloadLength behaviour when using WebSocketServerSpec.compress(true) HOT 2
- Timeout leaves connection in the pool in configured state, blocking a pool slot HOT 17
- ERROR io.netty.util.ResourceLeakDetector - LEAK: ByteBuf.release() was not called before it's garbage-collected. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactor-netty.