赞
踩
我想在Chrome浏览器和Glassfish 4.1.1服务器之间创建websocket连接。 4天没有成功。 不幸的是,我得到HTTP 200消息,而不是101
铬DevTool日志:
"WebSocket connection to 'ws://DOMAIN_NAME:8080/serverendpointdemo/' failed:
Error during WebSocket handshake: Unexpected response code: 200"
客户端代码:
var ws = new WebSocket ("ws://" + document.location.host + "/serverendpointdemo/");
服务器端代码:
package com.za.tutorial.websocket;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/home/USER_NAME/glassfish4/glassfish/domains/domain1/applications/serverendpointdemo")
public class ServerEndpointDemo {
@OnOpen
public void handleOpen() {
System.out.println("Client is now connected...");
}
@OnMessage
public String handleMessage (String message) {
return null;
}
@OnClose
public void handleClose() {
}
@OnError
public void handleError (Throwable t) {
t.printStackTrace();
}
}
也许在这个问题上需要什么来帮助我? 请帮忙。
2016-07-26
Rinat
+0
我赢得这样说: 客户端的JavaScript代码: 变种WS =新的WebSocket( “WS:// DOMAIN_NAME:8080/serverendpointdemo/serverendpointdemo”); 帮助链接,如果elseone得到它: [链接](http://blog.martinandersson.com/making-a-java-ee-7-websocket-serverendpoint-class-discoverable/) [链接] (https://glassfish.java.net/docs/4.0/error-message-reference.pdf) [link](http://download.oracle.com/otn-pub/jcp/websocket-1_0-fr -eval-spec/JavaWebSocketAPI_1.0_Final.pdf?AuthParam = 1469574317_cf28b611d89626ae8c534e5f783409ca) –
+0
这是Glassfish服务器的一个特性。在GlassFish中,如果将应用程序与contextroot mycontextroot部署在侦听本地主机端口8080的Web容器中,则可以使用ws:// localhost:8080/mycontextroot/hello访问WebSocket。全文:[链接](http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html) –
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。