Running multiple SFS2X instances (Tomcat edition)

For those interested in running multiple SFS2X instances on the same machine we have a short guide on how to setup each server correctly avoiding port conflicts.

In particular since SFS2X 2.14 we have switched from Jetty to Tomcat for the HTTP-related services and our previous article on the same topic no longer applies.

» SmartFoxServer’s ports

SmartFoxServer binds port 9933 for both TCP and UDP so all we need is to use a different port value for every instance we intend to run on the same machine.

Typically we recommend incrementing by one the port number: 9933, 9934, 9935 etc. So it’s easy to remember which port to use for each instance.

» Tomcat’s ports

Tomcat uses a number of different ports:

  • 8080 for HTTP and WS (websocket)
  • 8443 for HTTPS and WSS (secure websocket)
  • 8005 which is referred to as the Shutdown port and is only bound locally (not exposed outside)

Here we need a bit more planning to make sure that every instance is using unique port values for these services. Once again incrementing every port by one can be a simple system to manage these parameters.

» How to proceed

Launching the first instance doesn’t pose any issues as you can leave all default port values and the server will run just fine. However, when it’s time to launch the second instance you will need to manually edit a few files to configure the ports differently.

SmartFoxServer

Navigate your file system and locate the SmartFoxServer installation folder. From there open the server.xml file located under SFS2X/config/

At the top of the file you will find this section:

<socketAddresses>
     <socket address="0.0.0.0" port="9933" type="TCP"/>
     <socket address="127.0.0.1" port="9933" type="UDP"/>
</socketAddresses>

where you can configure the port numbers to your needs.

Tomcat

The configuration file to open is located under SFS2X/lib/apache-tomcat/conf and is called, unsurprisingly, server.xml

Here you will have to look for all the uncommented <Connector … blocks that can be found. Here’s how they look like:

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

Out of the box you will find two, one set on TCP port 8080 for HTTP and another one set on TCP port 8443 for HTTPS.

Also notice how the redirectPort attribute references the HTTPS port value. Make sure to change this as well, reflecting the new port numbers.

Finally look for this XML snippet:

<Server port="8005" shutdown="SHUTDOWN">

This is the aforementioned Shutdown port which also requires its unique value.

Now it is time to save the config and start the second SmartFoxServer instance.

If you need to run even more instances on the same local machine you will just need to repeat this process once again choosing more unique port values.

» Firewall Notes

Running multiple server instances on the same machine doesn’t pose particular issues in terms of firewall rules, if you plan to also test locally (i.e. on the same machine).

However if you need external clients to reach the servers then make sure that all ports in use by all instances are configured in your firewall rules.