Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

36
LINES

< > BotCompany Repo | #237 - Brain protocol, JSON version, v2

Document

Basic protocol
--------------

Everything takes place over TCP/sockets. Communication is always between a "client" and "brain" (server) which one or more TCP connections between them.

Each client or brain line is a one-line JSON array.

Brain lines:
['answers', '#cmd1', [['#3', 'OK', 'ok'], ['#4', 'Int', '10']] -- asynchronous answers to a command, each object with type and desc
['error', 'copy of line', 'error text'] -- report error in the client line

Client lines:
['cmd', '#receiver', commandAsJSONArray] -- send command
['forget', ['#3', '#4']] -- discard object references
['exit'] -- complete this talk

Commands are numbered from 1 up per talk (#cmd1, #cmd2 etc), so there is no need for the client to transmit the ID.

There is always an initial object on the brain side called #start that the client can send commands to. #start has type "Start", description "start" and no help text.

(Having #start is a simpler approach than the initial-objects command in v1. It also makes making a facade easier because it can produce a #start object without any information on the brain it facades/will facade.)

The "info" command is not currently used. We can supercede it with ThingStandardCommands (_desc etc). It used to look like that:

--['info', ['#3']] -- get info on objects (type, description, pointers)
--['info', '#3'] -- shorter syntax for only one object

--['info', [['#3', 'OK', 'ok', 'a', 'b', 'c', 'd']]] -- answer to info request: id, type, desc, pointers


Advanced notes
--------------

The protocol can be used bidirectionally if you like that sort of thing, with both parties being client and server (or the 'brain'). The two different 'info' lines (request vs answer) can be distinguished by the argument format (just id or id plus 3 more fields).

Using the protocol bidirectionally in one connection could also allow the client to introduce itself via an initial object. Whatever the format for that is. Maybe "#i-am" with type "IAm" and description "brain client bla version x running on this and that server".

Author comment

Supercedes #235

download  show line numbers   

Travelled to 8 computer(s): aoiabmzegqzx, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Image recognition results

Recognizer Recognition Result Visualize Recalc
#308 2077 [visualize]

Snippet ID: #237
Snippet name: Brain protocol, JSON version, v2
Eternal ID of this version: #237/1
Text MD5: e03b33d76384888b5bf75e17fd0b06ed
Author: stefan
Category: basic brain design :o)
Type: Document
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2014-10-06 19:22:21
Source code size: 2077 bytes / 36 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 661 / 102
Referenced in: #235 #3000189 #3000202 #3000238 #3000382 #3000383

Formerly at http://tinybrain.de/237 & http://237.tinybrain.de