Can self hosted SignalR on the Raspberry Pi work?

2019-03-29 15:59发布

I want to have a C#/mono/signalR based web page hosted on the Raspberry Pi - is this possible?

I have managed to write a client-server-client solution where the signalR hub is hosted on a PC running IIS 8. A console app on the pi connects to the server hub with the c# signalR client. The asp.net server also hosts a 'remote control' page for a browser client to send commands to the pi but now I want to eliminate the PC as a requirement and have everything hosted on the pi.

1条回答
小情绪 Triste *
2楼-- · 2019-03-29 16:51

TLDR

It can be done! Video. Code.

Long story

I managed to get a solution working with Nancy, SignalR and the OWIN based webserver NoWin running from a console app on the Rasperry Pi (mono 3, hard float). See the RPi.Nancy project in this solution:

https://github.com/neutmute/RPi.Demo

Compared to being a pure client connected to an IIS SignalR host, the pi as a self hosted web server is somewhat more laggy. The response from a knockout.js bound range slider is very slow taking several seconds for the stream of updates to finish feeding through to the server after it has stopped moving on the client. Running the same self hosted server on a PC also demonstrates some lag, but not as slow as on the Pi.

While running the self hosted signalR, the mono process conumes 97% while the slider is being dragged and transmitting a stream of signalR events. This does not happen when in pure client mode with IIS as the hub server, however the IIS server does experience high CPU usage when there is furious dragging of the slider, so perhaps the pi should be forgiven for a little lag.

I also tried Katana as the webserver but it ran even slower than NoWin.

Note that the entirely self hosted SignalR solution would work fine if one only was sending a few button presses here and there - the lag is apparent only when dragging a slider back and forth and having a continual stream of events generated. One solution may be to throttle the updates from the slider via the knockout bindings and reduce the resolution of the slide events.

Also of note is that SignalR when hosted on the pi can not use web sockets as they are only available when SignalR is hosted on IIS 8. Server Side Event transport is used instead. This is the same transport when in pure client mode.

查看更多
登录 后发表回答