A new websocket-based ability to enable PyNARS communicate with Web client #36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
This comes from a comment on issue #35, in which I considered to make a websocket-based IO channel for PyNARS based on
websockets
.After reading Bowen Xu's reply, I think aio_rpc is related to "socket" rather than "websocket", which is a duplex communication protocol built on modern Web technology.
So aiming to improve the ability of connecting to other clients (such as web browser), I added a new cmd
server-websocket
to implement this ability, and made it optional with dynamic imports (so there is no need to force changes to PyNARS dependencies).Overview
Optimized
ConsolePlus
and some fixesInterface.py
(by enhances functionregister_interface
)Console.py
(New) cmd
server-websocket
: Set up a WebSocket-based server using packagewebsockets
ConsolePlus
via WS connection "ws://[server address]:[server port]" (it can be set by user) and input Narsese/cmd, just like directly input on the command line.[{"interface_name": str, "output_type": str, "content": str}, ...]
[{"interface_name": "initial", "output_type": "OUT", "content": "<B-->C>. %1.000;0.900%"}, {"interface_name": "initial", "output_type": "ANSWER", "content": "<B-->C>. %1.000;0.900%"}]
Previews
Test code of client
Client output
Server output