yeautyye / netty-websocket-spring-boot-starter Goto Github PK
View Code? Open in Web Editor NEW:rocket: lightweight high-performance WebSocket framework ( 轻量级、高性能的WebSocket框架)
License: Apache License 2.0
:rocket: lightweight high-performance WebSocket framework ( 轻量级、高性能的WebSocket框架)
License: Apache License 2.0
请问前端支持sockjs么?
如何能开启?
怎么在onopen中获取自定义参数
有android+web前端+后台的demo吗?
请问如何支持wss?
maven打包时,@serverendpoint的host属性如果直接设置阿里云服务器公网ip,无法打包。
当我将host设置为0.0.0.0时,打包正常,客户端也能正常获取到推送的数据,但是会报一个远程主机强迫关闭了一个现有的连接。
2019-04-11 16:11:44.523 [nioEventLoopGroup-3-2] ERROR org.yeauty.pojo.PojoEndpointServer - Unexpected exception:
java.lang.NullPointerException: null
at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.yeauty.pojo.PojoEndpointServer.doOnError(PojoEndpointServer.java:134)
at org.yeauty.standard.HttpServerHandler.exceptionCaught(HttpServerHandler.java:96)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:264)
at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:256)
at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:264)
at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:256)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireExceptionCaught(CombinedChannelDuplexHandler.java:426)
at io.netty.channel.ChannelHandlerAdapter.exceptionCaught(ChannelHandlerAdapter.java:87)
at io.netty.channel.CombinedChannelDuplexHandler$1.fireExceptionCaught(CombinedChannelDuplexHandler.java:147)
at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at io.netty.channel.CombinedChannelDuplexHandler.exceptionCaught(CombinedChannelDuplexHandler.java:233)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:264)
at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:256)
at io.netty.channel.DefaultChannelPipeline$HeadContext.exceptionCaught(DefaultChannelPipeline.java:1401)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:264)
at io.netty.channel.DefaultChannelPipeline.fireExceptionCaught(DefaultChannelPipeline.java:953)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.handleReadException(AbstractNioByteChannel.java:125)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:174)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:628)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:563)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:480)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Unknown Source)
2019-04-11 16:11:44.807 [nioEventLoopGroup-3-3] ERROR org.yeauty.pojo.PojoEndpointServer - Unexpected exception:
java.io.IOException: 远程主机强迫关闭了一个现有的连接。
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(Unknown Source)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.read(Unknown Source)
at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1108)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:347)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:628)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:563)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:480)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Unknown Source)
项目部分附件如下
test.zip
client长时间不发送数据,再次发送数据时session.sendText()无效,重新关闭再打开时可用
netty server 如何主动向client 主动发送数据
The image sended is not displayed in the browser using the following code:
var ws = new WebSocket('ws://127.0.0.1:8080')
ws.binaryType = 'blob'
如题
你好,请问下“当地址相同,路径(path)不同时,使用同一个ServerBootstrap实例”,这句话怎么理解?
我的理解是:多@serverendpoint(path = UrlMappingConsts.V1_BOOTSTRAP)路径配置(地址+端口不变)那么他们的session是同一个? 可以这么理解吗
或者说我需要实现这种功能请问下你的框架是否支持?
Tips 我之所以想通过这种方式区分主要目的是能否让业务能单一化在某个类中。
我看了问题《一对一发消息应该怎么做》这边我发现貌似没办法通过 "/netty/{userId}" 这种方式把userId获取到对应的变量中去,不支持socket的PathParam注解啊。用“/netty”可以访问,用 "/netty/{userId}"直接报404.
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
if (frame instanceof TextWebSocketFrame) {
pojoEndpointServer.doOnMessage(ctx, frame);
return;
}
// 这里你直接给返回了 建议把此处单独拿出来 以及下面的Pong
if (frame instanceof PingWebSocketFrame) {
ctx.writeAndFlush(new PongWebSocketFrame(frame.content().retain()));
return;
}
if (frame instanceof CloseWebSocketFrame) {
ctx.writeAndFlush(frame.retainedDuplicate()).addListener(ChannelFutureListener.CLOSE);
return;
}
if (frame instanceof BinaryWebSocketFrame) {
pojoEndpointServer.doOnBinary(ctx, frame);
return;
}
if (frame instanceof PongWebSocketFrame) {
return;
}
}
请问server端如何获取到客户端的连接URL呢?
Hello,
is it possible to make path wildard I tried:
path =/**
I tried it like this but instead of wildcard it only allows me to create connection uwint path:
new WebSocket("ws://127.0.0.1:8085/**"); //javascript
new WebSocket("ws://127.0.0.1:8085/something/something /asd");//javascript this douesnt work
but it deonst work as expected
Thanks
spirng cloud gateway不支持呢。。。
你好,prefix配置无效。版本用的最新0.7.5
前端请求
socket = new WebSocket("wss://127.0.0.1:80/ws?userId=admin"); 会报错
但是socket = new WebSocket("ws://127.0.0.1:80/ws?userId=admin"); 不会报错 正常连接
我的理解https对应wss是不是理解错了?
后台必须是要https才能访问的
2018-12-03 23:07:47.280 DEBUG 46804 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0xeb16011e, L:/127.0.0.1:80] READ: [id: 0x8059199d, L:/127.0.0.1:80 - R:/127.0.0.1:56556]
2018-12-03 23:07:47.281 DEBUG 46804 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0xeb16011e, L:/127.0.0.1:80] READ COMPLETE
2018-12-03 23:07:47.312 DEBUG 46804 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0xeb16011e, L:/127.0.0.1:80] READ: [id: 0x4e0e326c, L:/127.0.0.1:80 - R:/127.0.0.1:56557]
2018-12-03 23:07:47.312 DEBUG 46804 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0xeb16011e, L:/127.0.0.1:80] READ COMPLETE
可以支持获取请求参数吗?
有没有可以设置session最大大小的方法,tomcat的websocket是有这个方法的
@serverendpoint 注释的类 不支持 spring 的@Autowired?
如果不支持,有什么好的方位去实现,谢谢?
压缩逻辑的位置应该跟pipeline.addLast(new HttpServerHandler(pojoEndpointServer, config)); 平行.
.childHandler(new ChannelInitializer<NioSocketChannel>() {
@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(65536));
if (config.isUseCompressionHandler()) {
pipeline.addLast(new WebSocketServerCompressionHandler());
}
pipeline.addLast(new HttpServerHandler(pojoEndpointServer, config));
}
});
就是我客户端同样的页面同时打开三个,都是传同样的paramKey放到一个map里面,然后我在服务端从map取出这个paramKey的session发送消息,但是客户端只有某一个可以得到消息,有什么办法可以让所有页面都得到消息吗?
java.lang.IllegalStateException: Failed to register ServerEndpointConfig: org.yeauty.standard.ServerEndpointConfig@2caa5d7c
您好,请问做过压测什么的吗,或者有过生产实践没,各方面性能怎么样?
我想在连接开启的时候把session 和 用户token 做一个redis键值对保存。方便业务里面使用。但是session 没有提供序列化
想用这个做im,刚刚其他人的issuer说主动给client发消息,要接入kafka?
目前连接的数量我们在配置里有办法限制吗,另外如果没有配置直接限制的话,我们做服务治理就没法做了哈~
client在连接server的事件后,很快会触发一次异常,具体信息为【Connection reset by peer 】,server 端的连接处理并没有什么报错,难道是client的异常或者处理顺序导致的?求助~
怎样保持长连接,进行心跳检测呢。
您好,我现在要做两个人PK的答题游戏,大致流程如下
1、登录系统,标识为所有登录的人是在线的
2、某用户发起PK游戏,建立房间,给在线用户发起消息,最先进入的人与发起者进行游戏
3、系统推送题目给在同一房间的两个人,进行PK,相互推送答题结果
设计的时间怎么不兼容javax.websocket api,自己起了一套
你好,可以绑定spring boot web server 的端口吗?而不是新开端口?
应该可以通过设置setAllowedOrigins来设置,但是没有这个配置的地方
springboot 如何启动,pom文件中引用了spring-boot-starter和netty-websocket-spring-boot-starter这两个包,但是netty和websocket服务没有启动
我添加了一个切面,代码如下:
@Aspect
@Component
public class ServiceLogAspect {
@Around("execution(* com.test.server.WebSocketServer.onOpen(..))")
public Object around(ProceedingJoinPoint jp) throws Throwable {
Object result;
System.out.println("around");
try {
result = jp.proceed();
return result;
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
@OnOpen
public void onOpen(Session session, HttpHeaders headers, ParameterMap parameterMap) throws IOException {
System.out.println("session:" + session + ", new connection"); // not executed
@OnMessage
public void OnMessage(Session session, String message) {
System.out.println("session:" + session + ", message:" + message);
}
添加这个切面之后,@onopen函数就不触发了,around-advice中的代码也不会执行;但如果把切面中的onOpen函数换成onMessage函数则一切正常,around-advice中的代码也能够执行。
这是因为@onopen注解和aspectj注解有冲突吗?
之前本地测试的时候是ip连接,可以正常了解,现在发布外网,连接的是域名地址,连接失败,这个需要怎么配置支持吗?
能给一个demo吗?
文档中只说明了如何开始,没有说明如何关闭啊!
@serverendpoint(value = "/ws", host = "127.0.0.1", port = 3000)
前端访问响应403,后台无任何错误
启动日志:
2018-12-03 22:18:23.076 DEBUG 36760 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0x934e13e6] REGISTERED
2018-12-03 22:18:23.076 DEBUG 36760 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0x934e13e6] BIND: /127.0.0.1:3000
2018-12-03 22:18:23.080 DEBUG 36760 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0x934e13e6, L:/127.0.0.1:3000] ACTIVE
前端访问后响应403
GET ws://127.0.0.1:3000/ws?userId=2222222222 HTTP/1.1
Host: 127.0.0.1:3000
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
Upgrade: websocket
Origin: file://
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Sec-WebSocket-Key: IbOqN91LFZ1SCO6AVHXl0A==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
使用80端口正常连接
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.