61

I've seen signalR vs html5 websockets for asp.net MVC chat application but it doesn't 100% answer my question as it's based around HTML5 WebSockets, which Microsoft may have extended upon in .NET 4.5 with their WebSocket object.

I'm wondering if the WebSocket feature does actually do the same as SignalR and fall back to long polling when WebSockets aren't available? Surely Microsoft would implement the same technology as SignalR in their approach to this technology?

Edit:

For anyone else wondering about this, I found this comment the most helpful to understand the scenario and why I'll be using SignalR:

Well, they are not really. Up until now IIS and ASP.NET didn't have anything built in that supported WebSockets so SignalR project had to build it themselves. Now that Microsoft is providing the plumbing SignalR could easily switch to using Microsoft's implementation, either in addition to or instead of their own. SignalR is an abstraction over implementation details, WebScockets class is the implementation detail

Community
  • 1
  • 1
Chris Dixon
  • 9,147
  • 5
  • 36
  • 68
  • 1
    As mentioned originally in the answer, the plan for SignalR was to be part of .NET, which did happen as it's now an official part of ASP.NET http://asp.net/signalr - I updated my answer to add the link and thought you might like to know. – Meligy Apr 15 '13 at 23:08
  • Ahh, amazing! Thanks for the update on this @MohamedMeligy, it's really positive to see SignalR in the core library. – Chris Dixon Apr 16 '13 at 08:01

3 Answers3

46

I think SignalR is the way to go, and is going to be part of .NET itself anyway (and likely extend/merge/replace web-sockets support). It uses web sockets when it's supported, and consistent client polling hack when it's not, so, it's the way to go.

Update:

Since this answer is still getting upvoted, it's worth mentioning that SignalR is now officially part of ASP.NET.

Check http://asp.net/signalr

Update: .NET Core

SignalR is also being added to .NET Core as @yazanpro noted in comments.

It's available in .NET Core 2.1, and has official documentation as well.

Meligy
  • 35,654
  • 11
  • 85
  • 109
  • As much as I respect your answer here, do you know if WebSockets right now doesn't do the same? And if I was to use SignalR, if there's a potential merge of the technologies - would it be wise to use the SignalR library for now with this in mind? – Chris Dixon Mar 01 '12 at 22:16
  • 1
    The notes I have about this are from recent notes from Justin King from Microsoft when he presented SignalR in Sydney ALT.NET a few days ago. I understand that the merge of SignalR in .NET core is going to be by the SignalR guy himself, and hence is likely to be very few changes from current offering. – Meligy Mar 01 '12 at 22:39
  • Unbelievable they did not add SignalR support for websockets to Win7 and Server 2008. Outrageous really... – Dave Sep 09 '13 at 23:44
  • It's not a SignalR thing, it's an IIS thing, which signalR leverages. Websocket support was added in IIS 8 http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support – Meligy Sep 09 '13 at 23:55
  • At least SignalR has the best fallback when using an IIS version that doesn't support Websockets :S – Meligy Sep 09 '13 at 23:57
  • 1
    Well their bad to the IIS and socket folks then. I actually got a basic SignalR mechanism already implemented on my website in a couple hours, so kudos to the SignalR team. It uses SSE on Chrome and probably long polling on IE10 but at least my initial attempt worked right away. SignalR looks really nice so far! – Dave Sep 10 '13 at 01:24
  • It's also worth mentioning that the Javascript library for SignalR has a hard dependency on jquery.. So if you've developed your app with a different javascript library or framework, like React for instance, you're still going to have the dead weight of jquery holding your app back. – TheZanke Nov 29 '16 at 20:13
  • SignalR is now officially part of ASP.NET Core too: https://learn.microsoft.com/en-us/aspnet/core/signalr/?view=aspnetcore-2.1 And the official announcement: https://blogs.msdn.microsoft.com/webdev/2018/05/30/asp-net-core-2-1-0-now-available/ – yazanpro May 31 '18 at 00:58
31
  1. I'm wondering if the WebSocket feature does actually do the same as SignalR and fall back to long polling when WebSockets aren't available?

    WebSockets is a new protocol independent of other communication techniques. From the RFC

    The goal of this technology is to provide a mechanism for browser-based applications that need two-way communication with servers that does not rely on opening multiple HTTP connections (e.g., using XMLHttpRequest or s and long polling).

  2. Surely Microsoft would implement the same technology as SignalR in their approach to this technology?

    Not if they want to conform to the specification they won't. There's certainly nothing stopping Microsoft from developing a higher level API similar to SignalR that would abstract away communication detail and offer graceful fallback. However that hypothetical API would probably build on top of WebSocket class as opposed to replacing it.

Roman
  • 19,581
  • 6
  • 68
  • 84
  • 2
    I think the OP is referring to this: http://msdn.microsoft.com/en-us/library/system.net.websockets.websocket%28v=vs.110%29.aspx – BFree Mar 01 '12 at 22:02
  • Yep BFree, I am! Sorry if I was unclear in my question RomanArmy. – Chris Dixon Mar 01 '12 at 22:08
  • @thedixon I know, that's how I understood it too. I take the part of RFC that says *does not rely on ...* to mean the specification for WebSockets will not fall back to long poling. As such if Microsoft wants to conform to the specification, they will also not make their WebSocket class fall back to long poling. – Roman Mar 01 '12 at 22:17
  • So, in that regard, they're shooting their selves in the foot by being one step behind SignalR before they even begin with this technology if they plan on conforming WebSocket with the web specification? Trying to figure out what the future plan for Microsoft is really here. – Chris Dixon Mar 01 '12 at 22:24
  • 3
    @thedixon Well, they are not really. Up until now IIS and ASP.NET didn't have anything built in that supported WebSockets so SignalR project had to build it themselves. Now that Microsoft is providing the plumbing SignalR could easily switch to using Microsoft's implementation, either in addition to or instead of their own. SignalR is an abstraction over implementation details, WebScockets class **is** the implementation detail. – Roman Mar 01 '12 at 22:29
  • Ohhh, I understand now, thank you - that's a great answer. I wish I could mark both answers correct, but I'll go for this. – Chris Dixon Mar 01 '12 at 22:31
  • Yes great answer. I imagine the future of signalr will be to simply rip out their custom implementation and consume the new. NET APIs. – CatDadCode Sep 16 '12 at 23:58
11

SignalR uses OWIN which will use WebSockets connection if the browser supports web sockets and long polling if the browser doesn't support WebSockets.

wonea
  • 4,783
  • 17
  • 86
  • 139
Avi Ben-Margi
  • 167
  • 1
  • 3