在弹性beantalk中连接Web套接字时出错

时间:2018-09-26 07:20:07

标签: javascript java amazon-web-services websocket

我使用Java

创建Web套接字
package websocket;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.websocket.OnClose;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/ServerEndpoint")
public class ServerEndpoint{
    private static final Set<Session> SESSIONS = ConcurrentHashMap.newKeySet();

    @OnOpen
    public void onOpen(Session session) {
        SESSIONS.add(session);
        System.out.println(session+" :connected"); 
    }

    @OnClose
    public void onClose(Session session) {
        SESSIONS.remove(session);
        System.out.println(session+" :closed");
    }

    public static void sendAll(String text) {
        synchronized (SESSIONS) {
            for (Session session : SESSIONS) {
                if (session.isOpen()) {
                    session.getAsyncRemote().sendText(text);
                }
            }
        }
    }
}

可以使用javascript
连接Web套接字 如果我使用此链接

  

“ ws:// localhost:8080 / test / ServerEndpoint”

将项目部署到弹性beantalk之后
无法使用此插座

  

“ ws://samplepath.ap-northeast-1.elasticbeanstalk.com/ServerEndpoint”

这是错误消息

Error during WebSocket handshake: Unexpected response code: 404

我该怎么办?

0 个答案:

没有答案