Connecting to the CogServer

From OpenCog
(Redirected from Connecting to the Cogserver)

The CogServer, by default, listens for telnet connections on port 17001. After starting the CogServer, use telnet to connect to it. From from a separate terminal window, run

rlwrap telnet localhost 17001

You should be presented with:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
opencog>

Run "help"<enter> to get a list of commands. After additional modules are loaded, additional commands will appear.

Available commands:
 config:    Config a loaded module
 help:      List the available commands; print help for a specific command
 json:      Enter the JSON shell
 list:      List the currently loaded cogserver modules
 load:      Load a cogserver module
 py:        Enter the python shell
 py-eval:   Run a block of python code, and return immediately
 quit:      Close the shell connection
 scm:       Enter the scheme shell
 sexpr:     Enter the s-expression shell
 shutdown:  Shut down the cogserver
 stats:     Print some diagnostic statistics about the server.
 top:       Print server stats continuously
 unload:    Unload an opencog module

To get information about any of the commands, use "help <name of command>". For example

opencog> help scm                                                              
Usage: scm [hush|quiet|sync]                                                   
                                                                              
Enter the scheme interpreter shell. This shell provides a rich                 
and easy-to-use environment for creating, deleting and manipulating            
OpenCog atoms and truth values. It provides a full R5RS-compliant              
interactive scheme shell, based on the GNU Guile extension language.           
                                                                              
If 'hush' or 'quiet' is specified after the command, then the prompt           
will not be returned.  This is nice when catting large scripts using           
netcat, as it avoids printing garbage when the scripts work well.              
If 'sync' is specified after the command, then the output is sync,             
instead of async.                                                              

Telnet, UTF-8 and Readline bugs

There are assorted bugs that can bite.

telnet vs UTF-8

Not all versions of telnet are UTF-8 clean. These version will handle many or most UTF-8 strings, but not all. For example, in buggy versions, (Concept "“") will cause a ABORT: decoding-error ... Get out of this with a ctrl-C, and use netcat, instead. The problem is described here, in reddit.

The work-around is to use netcat, which is 8-bit-clean. Like so:

 rlwrap nc localhost 17001

This works great, except that sending ctrl-C to the CogServer is now harder: you have to send ctrl-V ctrl-C because a naked ctrl-C will just kill netcat.

rlwrap eats prompts

Some versions of rlwrap eat the prompt. This is described in a rlwrap bug report. This happens on Deian stable, with libreadline8 version 8.1 and rlwrap version 0.43.

There is no known workaround. Just squint your eyes and pretend everything is OK.