\n",
" \n",
"\\* Capabilities are supported on the client-side, but the wrapper session running on the server needs to support them as well.\n",
" \n",
"
"
]
},
{
"cell_type": "markdown",
"id": "636a3794-9070-4072-b8a6-acaad4b7ab95",
"metadata": {},
"source": [
"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](dataspace.ipynb) 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`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ec1eac03-b22c-4ade-b289-d071ef84aa86",
"metadata": {},
"outputs": [],
"source": [
"from simphony_osp.wrappers import Remote"
]
},
{
"cell_type": "markdown",
"id": "77132ffd-2e92-48d8-8405-abd5a82baa8c",
"metadata": {},
"source": [
"⠀"
]
},
{
"cell_type": "markdown",
"id": "192a82ff-6a2c-4a5d-bd66-95eb75365bc7",
"metadata": {},
"source": [
"**Configuration**"
]
},
{
"cell_type": "markdown",
"id": "b80236fd-2c4d-4d1f-88df-83984c4d82a9",
"metadata": {},
"source": [
"The [configuration string](introduction.ipynb) for the Remote wrapper is a [URI](https://www.ietf.org/rfc/rfc3986.txt) pointing to the server that hosts the remote wrapper session."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d7d4b9eb-b9fc-4604-b5ae-57be1442aa0e",
"metadata": {},
"outputs": [],
"source": [
"# needed to use the wrapper on a Jupyter notebook\n",
"import nest_asyncio\n",
"nest_asyncio.apply()\n",
"\n",
"remote = Remote('ws://username:password@127.0.0.1:4008', True)\n",
"# If you are running this page on Binder, do not run this cell until the server is running.\n",
"# Wait a few seconds after launching the server so that it has enough time to initialize."
]
},
{
"cell_type": "markdown",
"id": "e256fd5b-7e19-4253-870a-58f426f368e0",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "62ef6ffc-7f93-4c88-91e3-cdaf12dfc94a",
"metadata": {},
"outputs": [],
"source": [
"remote.close()"
]
},
{
"cell_type": "markdown",
"id": "c5b6d34e-561e-40f7-a825-34c987eb9cec",
"metadata": {},
"source": [
"## Server setup"
]
},
{
"cell_type": "markdown",
"id": "8b9dca67-553a-4350-8d6f-b0eee192da14",
"metadata": {},
"source": [
"To quickly fire up a server, use the function `simphony_osp.tools.host`."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c45d29a3-cb57-4e6c-a668-f00a1328fabf",
"metadata": {},
"outputs": [],
"source": [
"import multiprocess as multiprocessing # patched version of multiprocessing to work in Binder, use normal multiprocessing in your machine\n",
"\n",
"def launch_server():\n",
" from simphony_osp.tools import host\n",
" from simphony_osp.wrappers import Dataspace\n",
" \n",
" host(\n",
" Dataspace,\n",
" \"dataspace\",\n",
" True,\n",
" hostname=\"127.0.0.1\", # hostname to listen on\n",
" port=4008, # port to listen on\n",
" username=\"username\",\n",
" password=\"password\",\n",
" )\n",
" \n",
"multiprocessing.set_start_method(\"spawn\") # needed for the example to work in Binder\n",
"server = multiprocessing.Process(target=launch_server)\n",
"server.start()"
]
},
{
"cell_type": "markdown",
"id": "5fcb7efa-cd51-4a68-8b18-de7361276358",
"metadata": {},
"source": [
"
\n",
"
Note
\n",
"\n",
"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.\n",
" \n",
"However, if you take a look at [SimPhoNy's source code](https://github.com/simphony/simphony-osp/blob/v4.0.0/simphony_osp/tools/remote.py#L9), 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.\n",
" \n",
"