ESCP Engine Server Communication Protocol - nodechessengineserver/nceserv GitHub Wiki

ESCP - Engine Server Communication Protocol

Communication between the client and the server shold take place in the form of stringified JSON messages sent over the browser's built in websocket connection ( WebSocket ).

Every message should contain an "action" field which describes the operation that should be carried out and possibly further arguments depending on the type of the action.

Chess engines should be registered under a unique name, chosen by the user. The client then should reference an engine by this unique name. Every engine should have a path and a config parameter stored. The same physical engine ( under the same path ) can have several unique names, which allows to have different configurations of the same engine ( for example a multi variant engine can have multiple unique names for each variant, eg. Stockfish, Stockfish_Atomic etc. each with different config parameter ).

Action : string Direction Arguments Description
sendavailable client -> server none Requests the list of available engine names.
available server -> client available : string[] Sends the unique names of available engines in the form of a string array.
start client -> server name : string Starts the engine under the given unique name. Any previously started engine process will be terminated. At any given moment at most one engine can run. After starting the engine the content of the engine's config parameter will be written to the engine's standard input with a new line appended ( config itself can also contain new line characters, if multiple configuration commands are to be issued ).
issue client -> server command : string Issues a command to the engine by wriring it to its standard input. A new line character will be appended to the command.
thinkingoutput server -> client buffer : string A chunk of thinking output read from the standard output of the engine. Care should be taken so that each thinking output line is sent as a separate message.

A typical session should look like:

request: { "action" : "sendavailable" } // send available engines

response: { "action" : "available" , "available" : [ "Stockfish" , "Stockfish_Atomic" ] } // available engines: Stockfish, Stockfish_Atomic

request: { "action" : "start" , "name" : "Stockfish" } // starts Stockfish

request: { "action" : "issue" , "command" : "go infinite" } // instructs Stockfish to start analyzing

response: { "action" : "thinkingoutput" , "buffer" : "info depth 18 currmove d2d4 currmovenumber 4"} // a line of thinking output