wsync
1 Introduction
2 Installation
3 wsync command
4 wsync library
wsync
5 How to use the API
6 Clients and public servers
8.13.0.7

wsync🔗ℹ

Oscar Alberto Quijano Xacur

1 Introduction🔗ℹ

This package provides the server side of an API to make the server time in milliseconds available to clients.

This is useful for synchronizing actions on different computers.

The functioning is inspired by server-date for Node.js, with two important differences:

2 Installation🔗ℹ

In order to install wsync you need to have racket installed in your computer.

To install wsync you can use the raco command that comes with racket:

----------

 

   raco pkg install https://gitlab.com/oquijano/wsync.git

 

----------

After installing, in order to run the wsync command, you need to add the racket packages bin folder to your PATH environment variable. The following command gives you the path to that folder:

----------

 

   racket -e "(path->string (build-path (find-system-path 'addon-dir) (version) \"bin\"))"

 

----------

You can see the built-in help for the wsync command with

----------

 

   wsync -h

 

----------

3 wsync command🔗ℹ

The wsync command has one mandatory argument which is the port number to listen on. For example, the following command starts listening for connections on port 5000.

----------

 

   wsync 5000

 

----------

By default wsync only listens to connections from the localhost, if you would like to change that, you can use the option –host, which takes the ip of the device you want to listen on. If you want to listen on all network devices you can use the value ’0.0.0.0’. The following command accepts connections from all devices on port 5000.

----------

 

   wsync --host 0.0.0.0 5000

 

----------

4 wsync library🔗ℹ

If you want to run a server programmatically with racket you can use the server module from the wsync package, which only provides one function: wsync.

 (require wsync/server) package: wsync

procedure

(wsync port [listen-ip])  (-> any)

  port : listen-port-number?
  listen-ip : (or/c string? #f) = #f
Starts the wsync API server listening on ip listen-ip and port port. listen-ip should be the ip of the device one wants to listen for connections. If it is #f connections from all devices are accepted.

Once a connection is established to the server the only kind of message it accepts is a string containing a single number that should correspond to the current date in milliseconds of the client. The server answers back with a list converted to json containing the number received and the current date in milliseconds of the server.

It returns a function that when called stops listening on the provided port.

5 How to use the API🔗ℹ

The server only accepts Websocket connections to the base url (this is, "/"). Once the connection is started it only responds to messages consisting of a single number which should be a number that corresponds to current client epoch time in milliseconds. This is, the number of milliseconds elapsed since the midnight at the beginning of January 1st, 1970, UTC. Any other kind of message is ignored.

The server responds with a json string containing a vector with two elements. The first element is the number originally received form the client and the second one is the server epoch time in milliseconds.

6 Clients and public servers🔗ℹ

Currently there exists only one client written in JavaScript.

There exists also a public server running wsync that anyone can use to synchronize their events at https://wsync.net.