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
Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.NodeServices/README.md
+11-13Lines changed: 11 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -333,25 +333,23 @@ People have asked about using [VroomJS](https://github.com/fogzot/vroomjs) as a
333
333
334
334
### Built-in hosting models
335
335
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:
337
339
338
340
```csharp
339
-
services.AddNodeServices(options=>
340
-
{
341
-
options.HostingModel=NodeHostingModel.Socket;
342
-
});
341
+
usingMicrosoft.AspNetCore.NodeServices.Sockets;
343
342
```
344
343
345
-
**Available hosting models**
344
+
...then in your `Startup.cs` file's `ConfigureServices` method, you can configure:
346
345
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
+
```
353
351
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`.
0 commit comments