NutzCN Logo
问答 nutzboo配置websocket 出问题
发布于 1060天前 作者 wx_qlg2gnto8l47db98lo23 1862 次浏览 复制 上一个帖子 下一个帖子
标签:

出现问题:
js websocket:
WebSocket connection to 'ws://localhost:8888/erp/syscpuram' failed:

eclipse console:
[DEBUG] 17:05:54.917 org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:75) - Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@47331b3a:org.apache.tomcat.util.net.NioChannel@154e2fce:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8082 remote=/0:0:0:0:0:0:0:1:9846]], Status in: [OPEN_READ], State out: [OPEN] [DEBUG] 17:05:54.921 org.apache.coyote.AbstractProtocol$ConnectionHandler.release(AbstractProtocol.java:1017) - Pushed Processor [org.apache.coyote.http11.Http11Processor@1af5b2e] [DEBUG] 17:05:54.927 org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:718) - Processing socket [org.apache.tomcat.util.net.NioChannel@154e2fce:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8082 remote=/0:0:0:0:0:0:0:1:9846]] with status [OPEN_READ] [DEBUG] 17:05:54.927 org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:730) - Found processor [null] for socket [org.apache.tomcat.util.net.NioChannel@154e2fce:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8082 remote=/0:0:0:0:0:0:0:1:9846]] [DEBUG] 17:05:54.928 org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:799) - Popped processor [org.apache.coyote.http11.Http11Processor@1af5b2e] from cache
[DEBUG] 17:05:54.928 org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:537) - Error parsing HTTP request header
java.io.EOFException
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1294)
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1228)
at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:781)
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:370)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:502)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
[DEBUG] 17:05:54.930 org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:75) - Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@47331b3a:org.apache.tomcat.util.net.NioChannel@154e2fce:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8082 remote=/0:0:0:0:0:0:0:1:9846]], Status in: [OPEN_READ], State out: [CLOSED] [DEBUG] 17:05:54.931 org.apache.coyote.AbstractProtocol$ConnectionHandler.release(AbstractProtocol.java:1017) - Pushed Processor [org.apache.coyote.http11.Http11Processor@1af5b2e] [DEBUG] 17:05:54.942 org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:537) - Error parsing HTTP request header
java.io.EOFException
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1294)
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1228)
at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:781)
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:370)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:502)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
[DEBUG] 17:05:54.942 org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:75) - Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@6e92944c:org.apache.tomcat.util.net.NioChannel@507edfff:java.nio.channels.SocketChannel[connected local=/127.0.0.1:8082 remote=/127.0.0.1:9845]], Status in: [OPEN_READ], State out: [CLOSED] [DEBUG] 17:05:54.942 org.apache.coyote.AbstractProtocol$ConnectionHandler.release(AbstractProtocol.java:1017) - Pushed Processor [org.apache.coyote.http11.Http11Processor@1f1762c1] [DEBUG] 17:05:54.945 org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:537) - Error parsing HTTP request header
java.io.EOFException
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1294)
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1228)
at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:781)
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:370)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:502)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

按照文档步骤,一步一步来的,
入口类:

//ServerEndpoint是websocket的必备注解, value是映射路径, configurator是配置类.
@ServerEndpoint(value = "syscpuram", configurator=NutWsConfigurator.class)
@IocBean // 使用NutWsConfigurator的必备条件
public class SysWebSocket extends AbstractWsEndpoint{
	@OnOpen
    public void onOpen(Session session, EndpointConfig config) {
       System.out.println("1111111111111");
    }
}

js:

  var ws = new WebSocket(`ws://${window.location.host}/erp/syscpuram`);
    // 连接成功后,会触发onopen回调
    ws.onopen = function(event) {
        console.log("websocket onopen ...");
        // 加入home房间
        ws.send(JSON.stringify({room:'home',"action":"join"}));
    };

nginx配置:

 listen       8888;
       location /erp {
          proxy_pass http://localhost:8082/;
          #proxy_read_timeout 60m;
          proxy_read_timeout 3600s; 
          proxy_set_header Upgrade $http_upgrade;
          proxy_http_version 1.1;
          proxy_set_header Connection "upgrade";
        }

补充信息:
[INFO ] 17:20:58.117 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:55) - Nutz Version : 1.r.68-SNAPSHOT
[INFO ] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:56) - Nutz.Mvc[nutz] is initializing ...
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:60) - Web Container Information:
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:61) - - Default Charset : UTF-8
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:62) - - Current . path : C:\workspace_java\cserp.
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:63) - - Java Version : 1.8.0_121
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:64) - - File separator : \
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:65) - - Timezone : Asia/Shanghai
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:66) - - OS : Windows 10 amd64
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:67) - - ServerInfo : Apache Tomcat/8.5.57
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:68) - - Servlet API : 3.1
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:73) - - ContextPath :
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:74) - - context.tempdir : C:\Users\KaiHui\AppData\Local\Temp\tomcat.4405686416431582350.8082\work\Tomcat\0.0.0.0\ROOT
[DEBUG] 17:20:58.118 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:75) - - MainModule : com.cs.cserp.MainLauncher

到底是哪里出了问题,求指点

3 回复

不要用localhost,用内网ip

不管用,换成jetty就没问题了

@wendal 打包成jar运行就报java.lang.NoClassDefFoundError: javax/websocket/server/ServerContainer是什么原因

java.lang.NoClassDefFoundError: javax/websocket/server/ServerContainer
	at java.lang.Class.getDeclaredFields0(Native Method)
	at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
	at java.lang.Class.getDeclaredFields(Class.java:1916)
	at org.nutz.lang.Mirror._getFields(Mirror.java:578)
	at org.nutz.lang.Mirror.getFields(Mirror.java:541)
	at org.nutz.lang.Mirror.getFields(Mirror.java:527)
	at org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:132)
	at org.nutz.ioc.loader.annotation.AnnotationIocLoader.<init>(AnnotationIocLoader.java:49)
	at org.nutz.boot.NbApp.prepareIocLoader(NbApp.java:421)
	at org.nutz.boot.NbApp.prepare(NbApp.java:289)
	at org.nutz.boot.NbApp.execute(NbApp.java:201)
	at org.nutz.boot.NbApp.run(NbApp.java:182)
	at com.cs.cserp.MainLauncher.main(MainLauncher.java:39)
Caused by: java.lang.ClassNotFoundException: javax.websocket.server.ServerContainer
	at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 13 more

换成jetty了,在eclipse里启动没问题,打包成jar启动就报错

添加回复
请先登陆
回到顶部