# Implement a websocket servlet in a custom module

**URL:** <https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795>\
**Category:** Module Development\
**Created:** [July 28, 2014, 7:27am UTC](https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795 "2014-07-28T07:27:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MishaK](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@MishaK](https://forum.inductiveautomation.com/u/MishaK)\
**Post date:** [July 28, 2014, 7:27am UTC](https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795/1 "2014-07-28T07:27:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [July 28, 2014, 3:20pm UTC](https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795/2 "2014-07-28T15:20:44Z")

</div>

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](http://localhost:8088/main/System/MyServlet).  
(Note: I pulled this from [here](https://www.inductiveautomation.com/forum/viewtopic.php?f=74&t=11337), but that thread has a lot of unnecessary info)

Regards,

---

<div class="post-metadata">

**Author:** ![MishaK](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@MishaK](https://forum.inductiveautomation.com/u/MishaK)\
**Post date:** [July 28, 2014, 3:45pm UTC](https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795/3 "2014-07-28T15:45:08Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 27, 2014, 1:52pm UTC](https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795/4 "2014-10-27T13:52:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [November 7, 2014, 6:53pm UTC](https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795/5 "2014-11-07T18:53:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [November 10, 2014, 12:06pm UTC](https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795/6 "2014-11-10T12:06:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mlangdon](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@mlangdon](https://forum.inductiveautomation.com/u/mlangdon)\
**Post date:** [November 10, 2014, 3:31pm UTC](https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795/7 "2014-11-10T15:31:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [November 10, 2014, 3:36pm UTC](https://forum.inductiveautomation.com/t/implement-a-websocket-servlet-in-a-custom-module/8795/8 "2014-11-10T15:36:41Z")

</div>

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