Summary

Implementations

This in-page JavaScript implementation

./javascript_calculation.js. See also GitHub Project source for the same: https://github.com/paul-hammant/port-calculator/blob/master/javascript_calculation.js

Other Languages

TODO

Rationale/Problem

Solution

In the case of a default port for a technology, we could behave a CRC-16/ARC* conversion of the lowercase technology name or meaningful acronym or short version/

In the case of a port for a specific deployment of a service, we could behave a CRC-16/ARC* conversion of the domain name assuming that we can make unique domain names per service

* For either case, we do not desire a port number below 1024 and where we encounter that, just add 1024 to the previously calculated number. There's a case to be made for adding something like "a" to the string and running CRC-16/ARC again so the result is over 1024 (repeat until it is), but straight add of 1024 is easier.

Standard

If this ever gained wide adoption or a W3C standard, we could (framework/lang permitting) form URLs like so:

  1. http://hostname:a-term/path/to/resource

For technology 'Servirtium' the CRC-16/ARC* is 61417. These would be the equivalents under such a standard:

  1. http://hostname:servirtium/a/b/c.json
  2. - with a new W3C standard
  3. http://hostname:61417/a/b/c.json
  4. - as is today

As it happens testing technology Servirtium> did use this process to pick a default port number.

The Sinatra web framework for Ruby uses 4567 as the default port for non-production instances. Were they to go back in time and use this CRC-16/ARC* with the above 1024 trick instead of 4567 the calculation would yield 39192 (not quite so alluring).

  1. http://hostname:sinatra/hello
  2. - with a new W3C standard
  3. http://hostname:39192/hello
  4. - as is today or would be if the team hadn't picked 4567 already

History

Half baked idea that started this: I tweeted about not remembering a server technology's default port

Pseudocode

port_num = crc16Arc(term.to_lower_case())
if (number < 1024):
    port_num = port_num + 1024