mj_Network Configuration

MahJonggPro enables multiple people to play over the internet.  There are four network options.  Multiple options are supported because no single option has all the best features or would be available to everyone.  The options vary in availability, speed, and stability.  The speedier options tend to have lower availability.  The options are described here in order of decreasing availability and increasing speed. The server option speeds depend on server responsiveness.  A high data rate is not required, but if the server responds slowly, the game will be slow.  The direct connect option speed only depends on the connecting device’s internet speeds.  Direct connect means the player’s devices communicate directly without a 3rd-party server relaying the messages.  This is called Peer-to-Peer (P2P). The external server options all relay messages between players through an external “third-party” server.

External Server Options:  There are many free or low-cost servers available on the internet.  Table D-1 compares a few low or no-cost servers.  There are many other features to compare, but those listed are the most important for using MahJonggPro.  Some hosts do not allow running a game server script that is not in direct support of a web page.  The web page version can also be uploaded to these servers.  Most other features are only important if you are also hosting a website under the same account.  A new server account can usually be created and configured to use MahJonggPro in less than 5 minutes.  X10Hosting is the default MahJonggPro HTTP protocol server (MahJonggPro.x10.mx).  MahJonggPro does not currently support the older FTP protocol, but I may add it to use with the X10Hosting server.  A 000webhost MahJonggPro HTTP server is available (for 1 year) at MahJonggPro.000webhostapp.com.  To select a different HTTP server in MahJonggPro, set the Network Type to Server, Net Protocol to HTTP, Server Type to Custom, and Account Type to Not Required, then enter the server internet address (without the http://) in the address field.

Table D-1.  External Server Options

CompanyFree Trial?Min. Cost/Mo.SpeedBandwidth Limit (GB/Mo.)Protocols Supported
X10HostingYesFreeVery FastNoneHTTP, FTP
000webhost1 Year$3.99Fast3 (~100 games)HTTP(S)
IONOSNo$4 for 6 Mo. Then $6ModerateNoneHTTP(S), SSH, SFTP

An example network configuration input is shown in Figure D1. The network control inputs are:

  1. Network Type – This can be None, Server(S), or Direct(D). 
  2. Net Protocol – The network protocol options are: UDP and TCP for direct connection; and HTTP, HTTPS, Secure Shell (SSH), and Secure File Transfer Protocol (SFTP) for an external server.  HTTPS is an encrypted (secure) version of HTTP, but there should be no need to encrypt the game data.
  3. Account Type – This can be Public, or Private.  The public HTTP server can be either Default/Guest or Not Required.  A server requiring account login can be used by selecting Private and providing account information.  An SSH or SFTP server must use a Private account.
  4. Show Status – Status can be: Off, On:No Display, On:Box, or On:Heart.  The external server options can send special messages to detect when players have disconnected or are unresponsive.  The “On” options use these special “Heartbeat” messages.  The external server status also shows information about internal game status (only useful for debugging and knowing the other players are still active).  The “Heartbeat” icon can be either a Box or a Heart.  The Monitor and Timeout inputs below the “Show Status” input set the period (seconds) between heartbeat messages and the period (seconds) before a device times out.  When a host device times out, the other players become single player games.  If a client device times out, it is replaced by a computer player.
  5. LAN Prefix – For Direct Network Type, the first two or more digits of any LAN IP addresses (for example: 10.0. if the LAN IP addresses are 10.0.0.XXX).  This is only needed for direct connections and only if multiple players are playing on a LAN and are not using IPv6 addresses.

Option 1.  External HTTP Server (S/HTTP or S/HTTPS)

All the multiplayer options always use the HTTP protocol for game administration.  This included player information, global game configuration, and stored scores. 

If this option is selected then data is also transferred using HTTP or HTTPS during the game.  The S/HTTP option relays messages between players using Hypertext Transfer Protocol (HTTP). HTTPS is a secure version (encrypted), but it should not be necessary for any of the game messages to be encrypted.  Small text messages are sent between players through the server for multiplayer operation.  Figure D1 shows the network configuration popup setting for an HTTP server. 

The external HTTP server option can be slow, depending on server speed.  See above for some server options.  Acceptable speed for you depends on your experience.  The HTTP option is likely to be fast enough for beginner players or those just getting familiar with the MahJonggPro app.  The HTTP server option can use public web servers that run internet web sites.  HTTP is likely to be available and can connect with anyone with an internet connection.  If the HTTP protocol is not fast enough, the SSH (Option 3) or Direct (Option 4) protocols can be used, if available.

Figure D1.  Network Settings for Public HTTP External Server

Option 2.  External Private SFTP Server (S/SFTP)

The Secure File Transfer Protocol (SFTP) network option is slower than the HTTP protocol for playing a game, but is faster and better for exchanging custom voice files.  This interface requires a private external server with login and password. When using this interface voice files are automatically uploaded to the server after they are created if the voice permissions are not “None.”  The voice files are downloaded from the server instead of the host when clients are using the SFTP protocol.  SFTP transfers are faster because the files are transferred without having to convert them to text format.  Once the voice files are transferred for the players, a faster interface can be used to play the games. The setup is the same as for SSH shown in Figure D3, except the protocol is SFTP instead of SSH.

Before a game is played, users can start with the SFTP protocol enabled and download any available voice files from the server.  This is done using the player sets page shown in Figure D2. An FTP protocol option may be added in the future.

Figure D2. Player Sets Page with Player Selected for Voice Download

Option 3.  External Private SSH Server (S/SSH)

Figure D3 shows the network settings for an external server that uses a private server account and communicates with the server using the standard Secure Shell (SSH) protocol.  The shell type needs to be Bash or Bash-compatible.  Most game messages are the same small text messages as in the HTTP option.  As in the HTTP option, the game speed will depend on the responsiveness of the server.

The SSH server configuration uses:

  1. Address:  The address used to connect to the server.
  2. PHP Command: The command to run a command line version of the PHP protocol on the server.  PHP 4 or higher is required on the server.
  3. Login Page/Script: For the SSH server, this is the folder where the game server script is located.  Other game files are also created in this folder.
  4. User ID/Account: The account name or ID used to log in to the server.
  5. Password:  The password to access the server account.

You need to supply the above information, as is appropriate for the custom server. We do not offer a private server account to use.  The private server configuration data is saved in the user’s profile on their device, not on the server. The enter button reads and stores all the fields.  Alternatively, entering a carriage return stores just that entry.  The server’s login response is shown at the bottom right.

Figure D3. Network Setting for External Private SSH Server (S/SSH)

Private server accounts using SSH tend to be more responsive than public HTTP web servers.

Option 4.  Direct Connection (D)

Last, but not least, the direct option connects the players devices directly using the internet.  This would be the preferred option if it were not for internet firewalls.  I expect most people will not know how to or want to safely open a game port through a firewall. Firewalls are important to prevent hackers from accessing your device and are used by most or all internet routers and operating systems.

Some devices do not allow apps to change the router configuration or may have automated configuration disabled.  MahJonggPro will attempt to connect through the router’s firewall when a player is hosting on a direct network.  By default, most router firewalls reject all incoming messages that did not originate from the router itself.

If you know how and want to manually open a port through a router firewall, use port number 1909, app name “Godot”, and protocol “TCP”.

Even if you can’t open a port through a firewall, the direct connection is useful when the devices connecting are on the same side of the router firewall, i.e. on a local area network (LAN).  This is typical for multiple devices connecting through wi-fi within a house.  We use the direct connection when we play together at home.

Each client player exchanges messages only with the host.  The host device acts as a server and controls communication between all players.  The direct configuration setup is shown in Figure D4.  The recommended protocol is Transmission Control Protocol (TCP).  User Datagram Protocol (UDP) is also available for direct connection.  The devices’ internet addresses are determined automatically by MahJonggPro.  It may take longer to establish the direct connection due to the communication sequence required; however, the game should be fast after the connections are made.

The direct connection option still uses an external server for game administration. Game administration requires storing three small files on the server (user data, high score data, and game access settings).  Multiplayer game administration is described in the next section.

Figure D4.  Network Setting for Direct Connection (D/TCP)

MahJonggPro Multiplayer Game Administration

An internet server is made a MahJonggPro server by uploading a small PHP script.  This script handles all game communication and administration requests.  The server needs to be available via HTTP (and optionally SSH and/or SFTP).  After the script is uploaded, MahJonggPro will allow the first person who runs the app to create new users as described below.

MahJonggPro game administration uses a version of the Player Sets and Data display.  A non-administration version is used to log in or out of the game.  The game should have at least two administrators.  The administrators control who has game access and the user’s initial account information. Administrators should password-protect their accounts.

An example administration display is shown in Figure D5.  The blue area shows the administration data for all current users.  You can sort on a column by clicking on the column heading.  The columns are:

  1. Number:  A unique ID number assigned to each user. Numbers 0 and 1 are always administrators.
  2. Username:  A unique username for each user.  Case matters except for the first character.
  3. Name: A name for the user (not used except on this display and in the lobby)
  4. Last Login: Last date of login/use of the game
  5. Skill:  Skill level to help match players with similar skill and speed
  6. Location:  Geographical location
  7. Hrs. From Eastern Time:  Time Zone correction
  8. Cards: Mah Jongg card(s) available (year(s) or NMJL for all years)
  9. Active: Indication if the user is active (played recently)
  10. IP Status: User’s internet address types available (6=IPv6, 4=IPv4, L=On Same Local Area Network (LAN), off=not currently accessible)
  11. Network Name: Name assigned to a Server or Private Direct Internet connection
  12. Network Type/Protocol:  User’s last network type and protocol
  13. Admin:  Is the user an admin?
  14. Voice: Voice status: upload availability (R-restricted, P-Public) and currently downloaded (S-Specific/Restricted, C-Custom/Public)

Game administration functions are controlled by the buttons in the upper right area of Figure D4.  These functions are:

Min Password – The minimum required number of password characters for non-admin users is set here between 0 and 6.  If set to 0, no password is required.

User Control – Two user control features can be enabled or disabled, 1. Edit and 2. Create. Edit allows users to edit their own profile data. Create allows users to create and delete their own profile.

Clean – Clean compresses the user file so it has just two entries per user.  This should be done periodically to prevent it from getting too large.  Changes in user status add entries to this file.  The app may run the clean function automatically.

Edit – User data can be edited by an admin or by the user if the “Edit” user control feature is enabled.  Selecting a user and pressing edit will bring up the additional display items shown in Figure D6. The username, name, location, time, skill, game, and admin values can be changed.  The password can also be reset to a default value. Press either “Cancel” to cancel or “Enter” to complete editing the user’s data. Note: restart immediately after editing a user.

Add – Adds a new user.  Note: restart immediately after adding a user.

Delete – Deletes a user

Save – Stores a backup of the user data in a file

Restore – Restores user data from a backup file

Clear Scores – Clears the high score data

App Updates: The app does not automatically update itself; however, the administrator can set the latest version number on the web site so users are notified if a newer version is available.  If available, the new version number is shown above the logo at the lower left of the lobby.  An administrator can also post a message to all users using the bottom of the Figure D5 display.  The message is displayed in the lobby when a user logs in.

Figure D5.  Administration Display

Figure D6.  Administration Display Example when Editing a User