|
1 |
| -*channel.txt* For Vim version 7.4. Last change: 2016 Feb 04 |
| 1 | +*channel.txt* For Vim version 7.4. Last change: 2016 Feb 05 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar
|
@@ -32,7 +32,7 @@ $VIMRUNTIME/tools/demoserver.py
|
32 | 32 | Run it in one terminal. We will call this T1.
|
33 | 33 |
|
34 | 34 | Run Vim in another terminal. Connect to the demo server with: >
|
35 |
| - let handle = ch_open('localhost:8765', 'json') |
| 35 | + let handle = ch_open('localhost:8765') |
36 | 36 |
|
37 | 37 | In T1 you should see:
|
38 | 38 | === socket opened === ~
|
@@ -62,40 +62,54 @@ To handle asynchronous communication a callback needs to be used: >
|
62 | 62 | Instead of giving a callback with every send call, it can also be specified
|
63 | 63 | when opening the channel: >
|
64 | 64 | call ch_close(handle)
|
65 |
| - let handle = ch_open('localhost:8765', 'json', "MyHandler") |
| 65 | + let handle = ch_open('localhost:8765', {'callback': "MyHandler"}) |
66 | 66 | call ch_sendexpr(handle, 'hello!', 0)
|
67 | 67 |
|
68 | 68 | ==============================================================================
|
69 | 69 | 2. Opening a channel *channel-open*
|
70 | 70 |
|
71 | 71 | To open a channel: >
|
72 |
| - let handle = ch_open({address}, {mode}, {callback}) |
| 72 | + let handle = ch_open({address} [, {argdict}]) |
73 | 73 |
|
74 | 74 | {address} has the form "hostname:port". E.g., "localhost:8765".
|
75 | 75 |
|
76 |
| -{mode} can be: *channel-mode* |
77 |
| - "json" - Use JSON, see below; most convenient way |
| 76 | +{argdict} is a dictionary with optional entries: |
| 77 | + |
| 78 | +"mode" can be: *channel-mode* |
| 79 | + "json" - Use JSON, see below; most convenient way. Default. |
78 | 80 | "raw" - Use raw messages
|
79 | 81 |
|
80 | 82 | *channel-callback*
|
81 |
| -{callback} is a function that is called when a message is received that is not |
| 83 | +"callback" is a function that is called when a message is received that is not |
82 | 84 | handled otherwise. It gets two arguments: the channel handle and the received
|
83 | 85 | message. Example: >
|
84 | 86 | func Handle(handle, msg)
|
85 | 87 | echo 'Received: ' . a:msg
|
86 | 88 | endfunc
|
87 | 89 | let handle = ch_open("localhost:8765", 'json', "Handle")
|
88 | 90 |
|
89 |
| -When {mode} is "json" the "msg" argument is the body of the received message, |
| 91 | +"waittime" is the time to wait for the connection to be made in milliseconds. |
| 92 | +The default is zero, don't wait, which is useful if the server is supposed to |
| 93 | +be running already. A negative number waits forever. |
| 94 | + |
| 95 | +"timeout" is the time to wait for a request when blocking, using |
| 96 | +ch_sendexpr(). Again in millisecons. The default si 2000 (2 seconds). |
| 97 | + |
| 98 | +When "mode" is "json" the "msg" argument is the body of the received message, |
90 | 99 | converted to Vim types.
|
91 |
| -When {mode} is "raw" the "msg" argument is the whole message as a string. |
| 100 | +When "mode" is "raw" the "msg" argument is the whole message as a string. |
92 | 101 |
|
93 |
| -When {mode} is "json" the {callback} is optional. When omitted it is only |
| 102 | +When "mode" is "json" the "callback" is optional. When omitted it is only |
94 | 103 | possible to receive a message after sending one.
|
95 | 104 |
|
96 | 105 | The handler can be added or changed later: >
|
97 | 106 | call ch_setcallback(handle, {callback})
|
98 |
| -When {callback} is empty (zero or an empty string) the handler is removed. |
| 107 | +When "callback is empty (zero or an empty string) the handler is removed. |
| 108 | +NOT IMPLEMENTED YET |
| 109 | + |
| 110 | +The timeout can be changed later: > |
| 111 | + call ch_settimeout(handle, {msec}) |
| 112 | +NOT IMPLEMENTED YET |
99 | 113 |
|
100 | 114 | Once done with the channel, disconnect it like this: >
|
101 | 115 | call ch_close(handle)
|
|
0 commit comments