Racket  Script Universe
1 Getting Started
2 How does it work?
3 Differences from 2htdp/  universe
3.1 Differences for big-bang Function
register
3.2 Differences for universe Function
server-id
8.12

RacketScript Universe🔗ℹ

Ayden Diel <aydendiel@gmail.com>

 (require racketscript-universe)
  package: racketscript-universe

Experimental implementation of Racket’s 2htdp/universe library for RacketScript. Used to create distributed programs where both the server and the clients run in the browser.

1 Getting Started🔗ℹ

Since this library is just an implementation of 2htdp/universe, use those docs as your main reference. These docs will contain info about how racketscript-universe works and how it differs from the original, but won’t contain an in-depth API description.

See this example on github for one way of setting up your project.

To use the library, you need to be running a separate server (universe) and client (big-bang) instance at the same time, both in separate browser windows. You then need to pass the server’s peer id (which is currently "server" by default but will be changed) to the client’s big-bang call, and a connection will be established.

2 How does it work?🔗ℹ

We use PeerJS under the hood to mimic client-server behavior where both the client and server run in browser tabs. In reality everything is done with peer connections.

PeerJS’s PeerServer Cloud Serrvice handles all of the traffic behind the scenes so that you don’t have to worry about it.

3 Differences from 2htdp/universe🔗ℹ

In practice, this library only differs from 2htdp/universe when setting up connections (plus some slight differences in dependencies). Here’s everything you need to know on top of the original docs.

3.1 Differences for big-bang Function🔗ℹ

Original big-bang docs.

Differences from the original big-bang API include:

syntax

(register peer-id)

 
  peer-id : string?
Tells racket what the peer-id of the universe that you want your world to connect to, instead of an ip address. Because of this, racketscript-universe has no port clauses, as they’re not needed to connect via peer-id.

Because our peer connections are handled by one server in the cloud, clients can connect to servers on different networks as long as they know the server id.

3.2 Differences for universe Function🔗ℹ

Original universe docs.

  • The server-id clause can be used with universe to specify its peer id (which gets passed into the register clause of a big-bang call). Note that two servers should not have the same peer id, or problems will occur.

  • universe takes and optional #:dom-root keyword argument to specify a root element to insert the logging gui into.

  • No port clause.

  • No state clause (yet).

  • No to-string clause (yet).

  • No check-with clause (yet).

syntax

(server-id peer-id)

 
  peer-id : string?
Lets you specify the peer-id of the universe that you’re initializing. Use this peer-id with the register clause in a big-bang call to connect a client.