4

I have a websocket server deployed on Glassfish 4. I try to use ping/pong. My plan is to send periodically pings from the server to the clients and if they do not pong back I wan to close the conenction. Unfortunately there seem not do be any

@OnMessage
public void onMessage(PingMessage pingMessage)

within the javax.websocket.ClientEndpoint or ServerEndpoint.

Or any other way to react ping messages. For some very strange reasons, when I deploy the server inside Eclipse I receive pong messages even though I never implemented it inside the client. But when I deploy it using the glassfish maven plugin on my server, I dont receive any pongs anymore.

ThommyH
  • 310
  • 2
  • 6
  • 15
  • 1
    Are you sure that Glassfish is not pinging periodically your clients by itself? – vtortola Jun 25 '14 at 13:36
  • maybe but it is not returning any information about lost connections to the serverendpoint. unclosed sessions stay alive :( – ThommyH Jun 25 '14 at 22:34
  • Well, that and the fact that you are getting actual pongs in your handler... is quite odd, I mean, it should handle them transparently. I seems a little bit sloppy. – vtortola Jun 25 '14 at 22:46
  • according to [this answer from Tyrus dev to a similar question](https://stackoverflow.com/a/24438328/1220560) there's no API to handle pings as this is supposed to be always handled automatically by your websocket container. Therefore you should only need API to send pings and react to pongs. – morgwai Jul 23 '22 at 12:53

2 Answers2

2

It turned out that the server part was not fully deployed which caused the wierd difference between ecplise and the server. But anyway, it is still strange that you cannot handle the ping messages yourself. Imagine that you want to handle it or use it for sending status or something...

ThommyH
  • 310
  • 2
  • 6
  • 15
  • If you want to do that, that create your own ping pong messages. Why deviate from the spec and break backwards compatibility with alternate clients by changing what's built in. – Martin Konecny Aug 10 '15 at 23:34
  • I'm guessing the reason is that it is such a low level mechanism, that nobody thought you would like to react to it. same like there's no API to react to KEEP_ALIVE on TCP level. The only proper way to handle it, is to send PONG which is done by the container. Sending status should be implemented on application level of the protocol generally, not within a transport layer. – morgwai Dec 23 '20 at 01:22
0
public void onMessage(PongMessage pongMessage)
               throws IOException

https://tyrus.java.net/apidocs/1.4/org/glassfish/tyrus/ext/client/cli/ClientCli.ClientEndpoint.html

small_ticket
  • 1,910
  • 5
  • 22
  • 30