Skip to content

Commit eb98067

Browse files
Update docs about using socket transport. Fixesaspnet#500
1 parent a25d1f4 commit eb98067

File tree

1 file changed

+11
-13
lines changed
  • src/Microsoft.AspNetCore.NodeServices

1 file changed

+11
-13
lines changed

‎src/Microsoft.AspNetCore.NodeServices/README.md‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,25 +333,23 @@ People have asked about using [VroomJS](https://github.com/fogzot/vroomjs) as a
333333

334334
### Built-in hosting models
335335

336-
Normally, you can just use the default hosting model, and not worry about it. But if you have some special requirements, select a hosting model by setting the `HostingModel` property on the `options` object in `AddNodeServices`. Example:
336+
Normally, you can just use the default hosting model, and not worry about it. But if you have some special requirements, you can write your own hosting model, or reference a package that supplies one.
337+
338+
For example, you could use the 'socket' hosting model. It performs RPC between .NET and Node.js using a fast, low-level binary channel rather than the default HTTP transport. To do this, first install the NuGet package `Microsoft.AspNetCore.NodeServices.Sockets`. Then, at the top of your `Startup.cs` file, add:
337339

338340
```csharp
339-
services.AddNodeServices(options=>
340-
{
341-
options.HostingModel=NodeHostingModel.Socket;
342-
});
341+
usingMicrosoft.AspNetCore.NodeServices.Sockets;
343342
```
344343

345-
**Available hosting models**
344+
...then in your `Startup.cs` file's `ConfigureServices` method, you can configure:
346345

347-
*`Socket`
348-
* Launches Node as a separate process, and communicates with it using named pipes (on Windows) or domain sockets (on Linux / OS X).
349-
* This is faster than `Http` because it uses a low-level binary protocol with very low overhead. It retains one continuous connection for the whole lifetime of the Node instance, so it doesn't have to keep waiting for new connections to open.
350-
*`Http` (default)
351-
* Launches Node as a separate process, and communicates with it by making HTTP requests.
352-
* This primarily exists because it was implemented before `Socket`, but there's no particular reason to use it now that `Socket` is available. It could theoretically be useful if you wanted to run Node instances on separate servers (though there isn't currently any built-in API for configuring that).
346+
```csharp
347+
services.AddNodeServices(options=>{
348+
options.UseSocketHosting();
349+
});
350+
```
353351

354-
The default transport may change from `Http` to `Socket` in the near future, because it's faster.
352+
Now when you run your application, it will use the socket-based hosting and transport mechanism. In the past, the socket transport was faster than HTTP, but since .NET Core 1.1 improved the performance of `HttpClient` there isn't really any speed difference any more, so there's no longer any significant advantage to using `Microsoft.AspNetCore.NodeServices.Sockets`.
355353

356354
### Custom hosting models
357355

0 commit comments

Comments
(0)