java - Websocket - ServerEndpoint and ClientEndpoint does not exchange messages -
java - Websocket - ServerEndpoint and ClientEndpoint does not exchange messages -
i'm testing websockets glassfish 4 , "on board" implementation cannot send or receive messages although next tutorials the java ee 7 tutorial - sending , receiving messages or how build java websocket applications using jsr 356 api. want implement simple client server communication have a
server:
@serverendpoint("/echotest") public class server { private static final logger logger = loggerfactory.getlogger(server.class); @onopen public void onopen(session session) { logger.info("onopen invoked session '{}'.", session.getid()); seek { session.getbasicremote().sendtext("hello client!"); } grab (ioexception ex) { logger.error("message delivery failed.", ex); } } @onclose public void onclose(session session, closereason closereason) { logger.info("onclose invoked session '{}'; reason: {}.", session.getid(), closereason.getreasonphrase()); } @onmessage public void onmessage(session session, string msg) { logger.info("onmessage invoked session '{}'; message: {}.", session.getid(), msg); } }
and client:
@clientendpoint public class client { private static countdownlatch latch; private static final logger logger = loggerfactory.getlogger(client.class); @onopen public void onopen(session session) { logger.info("onopen invoked session '{}'.", session.getid()); seek { session.getbasicremote().sendtext("hello server!"); } grab (ioexception ex) { logger.error("message delivery failed.", ex); } } @onclose public void onclose(session session, closereason closereason) { logger.info("onclose invoked session '{}'; reason: {}.", session.getid(), closereason.getreasonphrase()); } @onmessage public void onmessage(session session, string msg) { logger.info("onmessage invoked session '{}'; message: {}.", session.getid(), msg); } public static void main(string[] args) { latch = new countdownlatch(1); websocketcontainer container = containerprovider.getwebsocketcontainer(); seek { container.connecttoserver(client.class, new uri("ws://localhost:8080/tstr/echotest")); latch.await(); } grab (deploymentexception | urisyntaxexception | interruptedexception | ioexception e) { logger.error("connection error occured!", e); } } }
the websocket available , can connect server (changing uri leads 404 handsheak error) none of (server sided) methods invoked , log message i'm getting is:
info: onopen invoked session 'acc92925-6682-4414-9e78-cf60a624b014'.
on client side. expect server @ to the lowest degree log onopen invokation. using (untouched) glassfish 4 netbeans 8 test.
any suggestions why there no messages exchanged?
your code works me, had replace logger (slf4j?) 1 java.util.logging.logger
java websocket glassfish jsr356
Comments
Post a Comment