Remote#

Binder

Capability

Support

Persistence

✓*

Files

✓*

Simulation

✓*

Cache

Note

* Capabilities are supported on the client-side, but the wrapper session running on the server needs to support them as well.

The Remote Wrapper is a special type of wrapper used to interact with a wrapper session that lives in a remote server. For example, a Dataspace wrapper session could be started on a remote server to let a single user store his/her data there. The Remote wrapper is included with SimPhoNy and available under simphony_osp.wrappers.Remote.

[1]:
from simphony_osp.wrappers import Remote

Configuration

The configuration string for the Remote wrapper is a URI pointing to the server that hosts the remote wrapper session.

[3]:
# needed to use the wrapper on a Jupyter notebook
import nest_asyncio
nest_asyncio.apply()

remote = Remote('ws://username:password@127.0.0.1:4008', True)
# If you are running this page on Binder, do not run this cell until the server is running.
# Wait a few seconds after launching the server so that it has enough time to initialize.

When the remote wrapper session is closed, only the connection is closed. The server will keep its wrapper session open and wait for a user to connect again.

[4]:
remote.close()

Server setup#

To quickly fire up a server, use the function simphony_osp.tools.host.

[2]:
import multiprocess as multiprocessing  # patched version of multiprocessing to work in Binder, use normal multiprocessing in your machine

def launch_server():
    from simphony_osp.tools import host
    from simphony_osp.wrappers import Dataspace

    host(
        Dataspace,
        "dataspace",
        True,
        hostname="127.0.0.1",  # hostname to listen on
        port=4008,  # port to listen on
        username="username",
        password="password",
    )

multiprocessing.set_start_method("spawn")  # needed for the example to work in Binder
server = multiprocessing.Process(target=launch_server)
server.start()

Note

The server on this example works for just one user. SimPhoNy does not include a method to spawn a server that can be used by multiple users.

However, if you take a look at SimPhoNy’s source code, you will realize that most of the pieces of the puzzle are already there, so it would be relatively simple to modify the host function to achieve such goal.