我使用Java
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
我该怎么办?