{"id":1705,"date":"2021-06-23T08:16:07","date_gmt":"2021-06-23T08:16:07","guid":{"rendered":"https:\/\/smartfoxserver.com\/blog\/?p=1705"},"modified":"2022-04-12T14:30:19","modified_gmt":"2022-04-12T14:30:19","slug":"running-multiple-sfs2x-instances-tomcat-edition","status":"publish","type":"post","link":"https:\/\/smartfoxserver.com\/blog\/running-multiple-sfs2x-instances-tomcat-edition\/","title":{"rendered":"Running multiple SFS2X instances (Tomcat edition)"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>In particular <strong>since SFS2X 2.14<\/strong> we have switched from <strong>Jetty<\/strong> to <strong>Tomcat<\/strong> for the HTTP-related services and our <a href=\"https:\/\/smartfoxserver.com\/blog\/running-two-sfs2x-instances-on-the-same-machine\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"previous article (opens in a new tab)\">previous article<\/a> on the same topic no longer applies.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h3 id=\"smartfoxserver-s-ports\">\u00bb SmartFoxServer&#8217;s ports<\/h3>\n\n\n\n<p>SmartFoxServer binds port <strong>9933<\/strong> for both <strong>TCP<\/strong> and <strong>UDP<\/strong> so all we need is to use a different port value for every instance we intend to run on the same machine.<\/p>\n\n\n\n<p>Typically we recommend incrementing by one the port number: 9933, 9934, 9935 etc. So it&#8217;s easy to remember which port to use for each instance.<\/p>\n\n\n\n<h3 id=\"tomcat-s-ports\">\u00bb Tomcat&#8217;s ports<\/h3>\n\n\n\n<p>Tomcat uses a number of different ports:<\/p>\n\n\n\n<ul><li><strong>8080<\/strong> for HTTP and WS (websocket)<\/li><li><strong>8443<\/strong> for HTTPS and WSS (secure websocket)<\/li><li><strong>8005<\/strong> which is referred to as the <em>Shutdown port<\/em> and is only bound locally (not exposed outside)<\/li><\/ul>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 id=\"how-to-proceed\"> \u00bb How to proceed<\/h3>\n\n\n\n<p>Launching the first instance doesn&#8217;t pose any issues as you can leave all default port values and the server will run just fine. However, when it&#8217;s time to launch the second instance you will need to manually edit a few files to configure the ports differently.<\/p>\n\n\n\n<p><strong>SmartFoxServer<\/strong><\/p>\n\n\n\n<p>Navigate your file system and locate the SmartFoxServer installation folder. From there open the <strong>server.xml<\/strong> file located under <strong>SFS2X\/config\/<\/strong><\/p>\n\n\n\n<p>At the top of the file you will find this section:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;socketAddresses&gt;\n     &lt;socket address=\"0.0.0.0\" port=\"9933\" type=\"TCP\"\/&gt;\n     &lt;socket address=\"127.0.0.1\" port=\"9933\" type=\"UDP\"\/&gt;\n&lt;\/socketAddresses&gt;<\/pre>\n\n\n\n<p>where you can configure the port numbers to your needs.<\/p>\n\n\n\n<p><strong>Tomcat<\/strong><\/p>\n\n\n\n<p>The configuration file to open is located under <strong>SFS2X\/lib\/apache-tomcat\/conf<\/strong> and is called, unsurprisingly, <strong>server.xml<\/strong><\/p>\n\n\n\n<p>Here you will have to look for all the uncommented <strong>&lt;Connector &#8230;<\/strong> blocks that can be found. Here&#8217;s how they look like:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;Connector connectionTimeout=\"20000\" port=\"8080\" protocol=\"HTTP\/1.1\" redirectPort=\"8443\"\/&gt;<\/pre>\n\n\n\n<p>Out of the box you will find two, one set on <strong>TCP port 8080<\/strong>  for HTTP and another one set on <strong>TCP port 8443<\/strong> for HTTPS.<\/p>\n\n\n\n<p>Also notice how the <em>redirectPort<\/em> attribute references the HTTPS port value.  Make sure to change this as well, reflecting the new port numbers.<\/p>\n\n\n\n<p>Finally look for this XML snippet:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;Server port=\"8005\" shutdown=\"SHUTDOWN\"&gt;<\/pre>\n\n\n\n<p>This is the aforementioned <em>Shutdown port<\/em> which also requires its unique value.<\/p>\n\n\n\n<p>Now it is time to save the config and start the second SmartFoxServer instance. <\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 id=\"firewall-notes\">\u00bb Firewall Notes<\/h3>\n\n\n\n<p>Running multiple server instances on the same machine doesn&#8217;t pose particular issues in terms of firewall rules, if you plan to also test locally (i.e. on the same machine).<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[66,7,116],"_links":{"self":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/1705"}],"collection":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/comments?post=1705"}],"version-history":[{"count":19,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/1705\/revisions"}],"predecessor-version":[{"id":2237,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/1705\/revisions\/2237"}],"wp:attachment":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/media?parent=1705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/categories?post=1705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/tags?post=1705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}