У меня есть клиент websocket , который подключается к серверу.
@ClientEndpoint
class WSClient {
private static Object waitLock = new Object();
@OnMessage
public void onMessage(String message) throws IOException {
System.out.println("Received msg: " + message);
}
private static void wait4TerminateSignal() {
synchronized (waitLock) {
try {
waitLock.wait();
} catch (InterruptedException e) {
}
}
}
public static void main(String[] args) {
WebSocketContainer container = null; //
Session session = null;
try {
//Tyrus is plugged via ServiceLoader API. See notes above
container = ContainerProvider.getWebSocketContainer();
//WS1 is the context-root of my web.app
//ratesrv is the path given in the ServerEndPoint annotation on server implementation
session = container.connectToServer(WSClient.class, URI.create("ws://localhost:8080/websocket"));
// message of bytes
session.getAsyncRemote().sendBinary(ByteBuffer.wrap(bytes));
wait4TerminateSignal();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
try {
session.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Затем он отправляет сообщение о том, что сервер принимает и продолжает процесс. Однако сервер отправляет обратно ответ, который должен быть обработан аннотированным методом @ OnMessage , однако ответа нет. Код сервера использует Spring и работает правильно - он отправляет сообщения другим клиентам, как и положено.
Спасибо за помощь!