带Web套接字的SignalR [英] SignalR with Web Sockets

查看:65
本文介绍了带Web套接字的SignalR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使Websocket在我的开发环境中工作:

I am attempting to get websockets working in my dev environment:

  • Visual Studio 2010
  • Windows 7
  • 信号R 0.51
  • 最新的Chrome/Firefox

不幸的是,Javscript客户端正在使用长时间轮询.当我在客户端强制使用网络套接字时,我根本无法连接:

Unfortunately the Javscript client is using long polling. When I force web-sockets on the client side I can't connect at all:

$.connection.hub.start({ transport: ['webSockets'] })

服务器代码是基于示例的自托管代码,如下所示:

Server code is self-hosted and based on the sample and looks like:

static void Main(string[] args)
{
    string url = "http://localhost:8081/";
    var server = new Server(url);

    // Map the default hub url (/signalr)
    server.MapHubs();

    // Start the server
    server.Start();

    Console.WriteLine("Server running on {0}", url);

    // Keep going until somebody hits 'x'
    while (true)
    {
        ConsoleKeyInfo ki = Console.ReadKey(true);
        if (ki.Key == ConsoleKey.X)
        {
            break;
        }
    }
}

public class MyHub : Hub
{            
    public void Send(string message)
    {
        Clients.addMessage(message);
    }
}

我到处搜寻,没有发现任何确定的内容.我是否需要指定一些额外的东西,使用Visual Studio 2012还是只能在Windows 8/IIS 8上使用?

I've searched around and found nothing definitive. Do I need to specify some extra things, use Visual Studio 2012 or will this only work on Windows 8 / IIS 8?

推荐答案

基于此答案 https://stackoverflow.com/a/9135334/700926 ,您将看到SignalR中的WebSocket支持依赖于Windows 8/IIS8-答案也指向SignalR的github页面上的Wiki页面,但是,该页面不再存在.

Based on this answer https://stackoverflow.com/a/9135334/700926 you will see that WebSocket support in SignalR relies on Windows 8 / IIS8 - the answer also points to a wiki page at SignalR's github page, however, that page does not exists anymore.

但是,通过在github上克隆wiki repo并返回一些修订,您将看到SignalR.WebSockets项目的文档,根据SignalR的github页面,该文档不再存在-(这可能解释了为什么删除Wiki网站的原因)-但是,在今年2月开始的SignalR.WebSockets维基页面的修订版中,它指出:

But, by cloning the wiki repo at github and go back some revisions you will see the documentation of the SignalR.WebSockets project which according to SignalR's github page, does not exist anymore - (which might explain why the wiki site is removed) - however, in a revision of the wikipage for SignalR.WebSockets from February this year, it stated that:

SignalR.WebSockets 可以将软件包添加到现有的SignalR项目中,以允许客户端 使用 WebSocket连接 协议. SignalR jQuery客户端将自动尝试通过WebSockets连接(如果 浏览器支持它),因此无需在客户端上进行任何更改 将WebSocket添加到基于SignalR的应用程序中.

The SignalR.WebSockets package can be added to an existing SignalR project to allow clients to connect using the WebSocket protocol. The SignalR jQuery client will automatically attempt to connect via WebSockets (if the browser supports it) so no changes are necessary on the client side to add WebSockets to your SignalR based application.

SignalR.WebSockets依赖 Microsoft.WebSockets 为了从内部监听传入的WebSocket连接 ASP.NET.该包又取决于新的WebSockets支持 已添加到ASP.NET 4.5和IIS 8.0中.结果, SignalR.WebSockets软件包仅适用于Windows 8计算机(.NET 4.5将安装在Windows的早期版本中,但IIS 8.0需要Windows 8.有关如何设置Windows的更多信息 8机(使用开发人员预览)请参阅 此处.

SignalR.WebSockets relies on Microsoft.WebSockets in order to listen for incoming WebSocket connections from within ASP.NET. This package in turn depends on the new WebSockets support that was added to ASP.NET 4.5 and IIS 8.0. As a result, the SignalR.WebSockets package will only work on a Windows 8 machine (.NET 4.5 will install on earlier versions of Windows but Windows 8 is required for IIS 8.0). For more information on how to setup a Windows 8 machine (using the developer preview) see here.

我尝试搜索比上面提供的信息新的信息,但是据我所知,SignalR Wiki在当前版本中并未明确涵盖此主题.

I have tried searching for newer information than what I have been able to provide above, but as far as I can tell, the SignalR wiki does not cover this topic explicitly in its current version.

这篇关于带Web套接字的SignalR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆