こんにちは、みんな!WebSocket接続に失敗しました:WebSocketハンドシェイク中にエラーが発生しました:予期しない応答コード:200
ChromeブラウザとGlassfish 4.1.1サーバーの間にwebsocket接続を作成しようとしています。そして4日は成功しません。
"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();
}
}
は残念ながら、私の代わりに101
クロームDevToolログのHTTP 200メッセージが表示されますこの質問に私を助けるためにあなたに何か他のものが必要ですか? 助けてください。
は、私はそれをこのように獲得しました。 参考リンク、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) – Rinat
これはGlassfishサーバーの機能です。 GlassFishでは、localhostのポート8080で待機しているWebコンテナにコンテキストルートmycontextrootを配置してアプリケーションをデプロイすると、ws:// localhost:8080/mycontextroot/helloを使用してWebSocketにアクセスできます。本文:[link](http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html) – Rinat