title: Grails 3, how to send/receive messages (not topics!) via web sockets
body: <p>Does anyone know of an example which has really simple onConnect onMessage onClose structure for use with grails-spring-websocket?</p>
  
  <p>The first problem when trying to implement web sockets in grails 3 is which plugin library to use. It needs to be one which will be supported in grails so it gets new versions, and one which has lots of users, examples and/or documentation.</p>
  
  <p><a href="http://caseyscarborough.com/blog/2014/12/07/using-websockets-in-grails/" rel="nofollow noreferrer">This article</a> has exactly what i need - the ability for users to connect, to store the list of connected users in a collection, for clients send messages to the server, and have the server send async "replies" back to one or small subset of the connected users.  But it uses an obscure socket implementation  (javax.websocket:javax.websocket-api:1.1) with grails.</p>
  
  <p>This one: <a href="https://plugins.grails.org/plugin/zyro/grails-spring-websocket" rel="nofollow noreferrer">https://plugins.grails.org/plugin/zyro/grails-spring-websocket</a> seems to be more popular, but all the examples I can find only cover publish/subscribe via topics, and don't have any connection to the individual client. While I could create a topic per client, this is far more complicated than it should be.  Also, configuration looks to be arcane and overly complex, there should be none.</p>
  
  <p>Someone suggested using the wschat plugin as a tictactoe game was done with it, but really I just need a simple socket implemenation with onConnect onMessage and onClose callbacks - no publish and subscribe, no topics etc.</p>
  
  <p>I implemented this in 5 minutes in node.js using the "ws" plugin, which is really simple, e.g.:</p>
  
  <pre><code>wss.on("connection", myFunction(ws) {..}
  ws.on('message', function(message) {
          messageHandler(message, ws)
      })
  ws.on('error', function(er) {
          console.log(er)
      })
  ws.on('close', function() {
          console.log('Connection closed')
  })
  </code></pre>
  
  <p>Is anything like this available in grails with an official web socket plugin, or should I stick to node for websockets? no security or other features are required (security is handled by passing user/pass down the secure socket in a "login" message - more or less the same as a web login)</p>
  
  <h1>Update</h1>
  
  <p>No luck yet finding a way to handle simple websocket events and to send web socket messages back to users.  <a href="https://github.com/zyro23/grails-spring-websocket" rel="nofollow noreferrer">This plugin</a> looked promising, but it only handles topics/queues.  The article mentioned earlier which uses javax.websocket-api is ugly but more or less what we need, but unfortunately as it is stand alone code, you cant access the database or services from the handlers, and services can't send messages.</p>