Implement a websocket servlet in a custom module

Team, I want to implement a servlet (in a custom module) that uses the websocket protocol. AFAIK, Tomcat has started support for websocket since version 7. Is Tomcat version 7 supported for Ignition? Is any developer guidance (i.e. examples, sample code) available for custom servlets?

Hi,

First off, not that it matters much if you’re sticking with servlets, but just so you know… in Ignition 7.7 we switched from tomcat to jetty.

Now, there’s not a real example as far as I know, but the basic procedure to add a custom servlet is pretty easy:

  1. Define your servlet
  2. Add it in your module’s gateway setup function:

@Override public void setup(GatewayContext context) { context.addServlet("MyServlet", MyServlet.class); }
It will be visible from http://localhost:8088/main/System/MyServlet.
(Note: I pulled this from here, but that thread has a lot of unnecessary info)

Regards,

Hi Colby,
thank you for the useful information.

Looking at the example: the class MyServlet should extend a class in the Servlet hierarchy, such as HTTPServlet, that is common for handling HTTP requests. However, in my case, I need to handle WebSocket communications. This can be done in Tomcat version 7 (but not in 6) by extending the servlet class named org.apache.catalina.websocket.WebSocketServlet.

I didn’t know about Jetty in Ignition 7.7. In case, do you know the Jetty version?

However, right now I am looking at an earlier Ignition that still uses Tomcat.
So, the residual question is: can Tomcat be upgraded to 7 (so to have WebSocket servlets) within Ignition, without loosing product support?

Regards,

Hi,
As a sequel to this question , are there any restrictions of using TCP/IP sockets in Ignition modules (Irrespective of Ignition version 7.6 or 7.7 or which ever web server) ? If yes then what are they?
Best Regards
PRAMANJ

No, there are no restrictions on using sockets in modules.

Hi Colby,
thanks for the confirmation. Kevin had also confirmed the same in another post of mine. However i have seen the sockets don’t work in a module when accessed by a client on a separate machne in the network. Whereas it works if its on the same host as the server in side an ignition module.

I have tested is several times! can you try once and reconfirm?

BR
PRAMANJ

I’ve personally implemented websockets (which uses TCP/IP sockets) in a module in Ignition. I had no problem communicating from remote devices.

  1. Pick a port not in use (I used 9000)
  2. Make sure that the port is not firewalled on the gateway machine

Ok let me probe further.
Thanks for your inputs.
BR
PRAMANJ