You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
Copy file name to clipboardExpand all lines: specs/HubProtocol.md
+70-16
Original file line number
Diff line number
Diff line change
@@ -20,10 +20,11 @@ This document describes three encodings of the SignalR protocol: [JSON](http://w
20
20
21
21
In the SignalR protocol, the following types of messages can be sent:
22
22
23
-
*`Negotiation` Message - Sent by the client to negotiate the message format
23
+
*`Negotiation` Message - Sent by the client to negotiate the message format.
24
24
*`Invocation` Message - Indicates a request to invoke a particular method (the Target) with provided Arguments on the remote endpoint.
25
25
*`StreamItem` Message - Indicates individual items of streamed response data from a previous Invocation message.
26
26
*`Completion` Message - Indicates a previous Invocation has completed, and no further `StreamItem` messages will be received. Contains an error if the invocation concluded with an error, or the result if the invocation is not a streaming invocation.
27
+
*`CancelInvocation` Message - Sent by the client to cancel a streaming invocation on the server.
27
28
28
29
After opening a connection to the server the client must send a `Negotiation` message to the server as its first message. The negotiation message is **always** a JSON message and contains the name of the format (protocol) that will be used for the duration of the connection. If the server does not support the protocol requested by the client or the first message received from the client is not a `Negotiation` message the server must close the connection.
29
30
@@ -41,9 +42,9 @@ Example:
41
42
42
43
## Communication between the Caller and the Callee
43
44
44
-
There a three kinds of interactions between the Caller and the Calle:
45
+
There are three kinds of interactions between the Caller and the Callee:
45
46
46
-
* Invocations - the Caller sends a message to the Calle and expects a message indicating that the invocation has been completed and optionally a result of the invocation
47
+
* Invocations - the Caller sends a message to the Callee and expects a message indicating that the invocation has been completed and optionally a result of the invocation
47
48
* Non-Blocking Invocations - the Caller sends a message to the Callee and does not expect any further messages for this invocation
48
49
* Streaming Invocations - the Caller sends a message to the Callee and expects one or more results returned by the Callee followed by a message indicating the end of invocation
49
50
@@ -74,7 +75,7 @@ The SignalR protocol allows for multiple `StreamItem` messages to be transmitted
74
75
75
76
On the Callee side, it is up to the Callee's Binder to determine if a method call will yield multiple results. For example, in .NET certain return types may indicate multiple results, while others may indicate a single result. Even then, applications may wish for multiple results to be buffered and returned in a single `Completion` frame. It is up to the Binder to decide how to map this. The Callee's Binder must encode each result in separate `StreamItem` messages, indicating the end of results by sending a `Completion` message.
76
77
77
-
On the Caller side, the user code which performs the invocation indicates how it would like to receive the results and it is up the Caller's Binder to determine how to handle the result. If the Caller expects only a single result, but multiple results are returned, the Caller's Binder should yield an error indicating that multiple results were returned. However, if a Caller expects multiple results, but only a single result is returned, the Caller's Binder should yield that single result and indicate there are no further results.
78
+
On the Caller side, the user code which performs the invocation indicates how it would like to receive the results and it is up the Caller's Binder to determine how to handle the result. If the Caller expects only a single result, but multiple results are returned, the Caller's Binder should yield an error indicating that multiple results were returned. However, if a Caller expects multiple results, but only a single result is returned, the Caller's Binder should yield that single result and indicate there are no further results. If the Caller wants to stop receiving `StreamItem` messages before the Callee sends a `Completion` message, the Caller can send a `CancelInvocation` message with the same `Invocation ID` used for the `Invocation` message that started the stream. It is possible to receive `StreamItem` messages or a `Completion` message after a `CancelInvocation` message has been sent, these can be ignored.
78
79
79
80
## Completion and results
80
81
@@ -223,6 +224,16 @@ S->C: Completion { Id = 42, Error = "Ran out of data!" }
223
224
224
225
This should manifest to the Calling code as a sequence which emits `0`, `1`, `2`, `3`, `4`, but then fails with the error `Ran out of data!`.
225
226
227
+
### Streamed Result closed early (`Stream` example above)
S->C: StreamItem { Id = 42, Item = 2} // This can be ignored
235
+
```
236
+
226
237
### Non-Blocking Call (`NonBlocking` example above)
227
238
228
239
```
@@ -248,7 +259,7 @@ Example:
248
259
```json
249
260
{
250
261
"type": 1,
251
-
"invocationId": 123,
262
+
"invocationId": "123",
252
263
"target": "Send",
253
264
"arguments": [
254
265
42,
@@ -261,7 +272,7 @@ Example (Non-Blocking):
261
272
```json
262
273
{
263
274
"type": 1,
264
-
"invocationId": 123,
275
+
"invocationId": "123",
265
276
"nonblocking": true,
266
277
"target": "Send",
267
278
"arguments": [
@@ -284,7 +295,7 @@ Example
284
295
```json
285
296
{
286
297
"type": 2,
287
-
"invocationId": 123,
298
+
"invocationId": "123",
288
299
"item": 42
289
300
}
290
301
```
@@ -305,7 +316,7 @@ Example - A `Completion` message with no result or error
305
316
```json
306
317
{
307
318
"type": 3,
308
-
"invocationId": 123
319
+
"invocationId": "123"
309
320
}
310
321
```
311
322
@@ -314,7 +325,7 @@ Example - A `Completion` message with a result
314
325
```json
315
326
{
316
327
"type": 3,
317
-
"invocationId": 123,
328
+
"invocationId": "123",
318
329
"result": 42
319
330
}
320
331
```
@@ -324,7 +335,7 @@ Example - A `Completion` message with an error
324
335
```json
325
336
{
326
337
"type": 3,
327
-
"invocationId": 123,
338
+
"invocationId": "123",
328
339
"error": "It didn't work!"
329
340
}
330
341
```
@@ -334,12 +345,26 @@ Example - The following `Completion` message is a protocol error because it has
334
345
```json
335
346
{
336
347
"type": 3,
337
-
"invocationId": 123,
348
+
"invocationId": "123",
338
349
"result": 42,
339
350
"error": "It didn't work!"
340
351
}
341
352
```
342
353
354
+
### CancelInvocation Message Encoding
355
+
A `CancelInvocation` message is a JSON object with the following properties
356
+
357
+
*`type` - A `Number` with the literal value `5`, indicationg that this is a `CancelInvocation`.
358
+
*`invocationId` - A `String` encoding the `Invocation ID` for a message.
359
+
360
+
Example
361
+
```json
362
+
{
363
+
"type": 5,
364
+
"invocationId": "123"
365
+
}
366
+
```
367
+
343
368
### JSON Payload Encoding
344
369
345
370
Items in the arguments array within the `Invocation` message type, as well as the `item` value of the `StreamItem` message and the `result` value of the `Completion` message, encode values which have meaning to each particular Binder. A general guideline for encoding/decoding these values is provided in the "Type Mapping" section at the end of this document, but Binders should provide configuration to applications to allow them to customize these mappings. These mappings need not be self-describing, because when decoding the value, the Binder is expected to know the destination type (by looking up the definition of the method indicated by the Target).
@@ -378,7 +403,7 @@ is decoded as follows:
378
403
379
404
*`0x95` - 5-element array
380
405
*`0x01` - `1` (Message Type - `Invocation` message)
381
-
*`0xa3` - string of length 3 (Target)
406
+
*`0xa3` - string of length 3 (InvocationId)
382
407
*`0x78` - `x`
383
408
*`0x79` - `y`
384
409
*`0x7a` - `z`
@@ -397,7 +422,9 @@ is decoded as follows:
397
422
398
423
`StreamItem` messages have the following structure:
399
424
425
+
```
400
426
[2, InvocationId, Item]
427
+
```
401
428
402
429
*`2` - Message Type - `2` indicates this is a `StreamItem` message
403
430
* InvocationId - A `String` encoding the Invocation ID for the message
@@ -414,7 +441,7 @@ is decoded as follows:
414
441
415
442
*`0x93` - 3-element array
416
443
*`0x02` - `2` (Message Type - `StreamItem` message)
417
-
*`0xa3` - string of length 3 (Target)
444
+
*`0xa3` - string of length 3 (InvocationId)
418
445
*`0x78` - `x`
419
446
*`0x79` - `y`
420
447
*`0x7a` - `z`
@@ -449,7 +476,7 @@ is decoded as follows:
449
476
450
477
*`0x94` - 4-element array
451
478
*`0x03` - `3` (Message Type - `Result` message)
452
-
*`0xa3` - string of length 3 (Target)
479
+
*`0xa3` - string of length 3 (InvocationId)
453
480
*`0x78` - `x`
454
481
*`0x79` - `y`
455
482
*`0x7a` - `z`
@@ -472,7 +499,7 @@ is decoded as follows:
472
499
473
500
*`0x93` - 3-element array
474
501
*`0x03` - `3` (Message Type - `Result` message)
475
-
*`0xa3` - string of length 3 (Target)
502
+
*`0xa3` - string of length 3 (InvocationId)
476
503
*`0x78` - `x`
477
504
*`0x79` - `y`
478
505
*`0x7a` - `z`
@@ -489,13 +516,40 @@ is decoded as follows:
489
516
490
517
*`0x94` - 4-element array
491
518
*`0x03` - `3` (Message Type - `Result` message)
492
-
*`0xa3` - string of length 3 (Target)
519
+
*`0xa3` - string of length 3 (InvocationId)
493
520
*`0x78` - `x`
494
521
*`0x79` - `y`
495
522
*`0x7a` - `z`
496
523
*`0x03` - `3` (ResultKind - Non-Void result)
497
524
*`0x2a` - `42` (Result)
498
525
526
+
### CancelInvocation Message Encoding
527
+
528
+
`CancelInvocation` messages have the following structure
529
+
530
+
```
531
+
[5, InvocationId]
532
+
```
533
+
534
+
*`5` - Message Type - `5` indicates this is a `CancelInvocation` message
535
+
* InvocationId - A `String` encoding the Invocation ID for the message
536
+
537
+
Example:
538
+
539
+
The following payload:
540
+
```
541
+
0x92 0x05 0xa3 0x78 0x79 0x7a
542
+
```
543
+
544
+
is decoded as follows:
545
+
546
+
*`0x92` - 2-element array
547
+
*`0x05` - `5` (Message Type `CancelInvocation` message)
548
+
*`0xa3` - string of length 3 (InvocationId)
549
+
*`0x78` - `x`
550
+
*`0x79` - `y`
551
+
*`0x7a` - `z`
552
+
499
553
## Protocol Buffers (ProtoBuf) Encoding
500
554
501
555
**Protobuf encoding is currently not implemented**
0 commit comments