SignalR OnConnected和OnDisconnected不点火 [英] SignalR OnConnected and OnDisconnected not firing

查看:3639
本文介绍了SignalR OnConnected和OnDisconnected不点火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用OnConnected麻烦和OnDisconnected在我的枢纽覆盖不点火。

I'm having trouble with OnConnected and OnDisconnected overrides in my Hub not firing.

有关复制的目的,我有一个非常简单的轮毂:

For replication purposes, I've got a very simple Hub:

public class OnlineHub : Hub
{
    public void TestMethod()
    {
        var a = 1;
    }

    public override System.Threading.Tasks.Task OnConnected()
    {
        return Clients.All.connected(Context.ConnectionId, DateTime.Now.ToString());
    }

    public override System.Threading.Tasks.Task OnDisconnected()
    {
        return Clients.All.disconnected(Context.ConnectionId, DateTime.Now.ToString());
    }
}

和一个aspx页面:

<script type="text/javascript">
    $(function () {
        $("#btn").click(function () {
            $.connection.onlineHub.server.testMethod();
        });

        $.connection.onlineHub.server.connected = function (id, date) {
            $("#results").append("connected: " + id + " : " + date + "</br>");
        };

        $.connection.onlineHub.server.disconnected = function (id, date) {
            $("#results").append(("connected: " + id + " : " + date + "</br>");
        };

        $.connection.onlineHub.connection.start();
    });

</script>

我使用jQuery 1.6.4和1.0.0 signalR-α2。客户端连接,并且不被执行断开的方法。如果我把一个断点OnConnected或OnDisconnected,断点不打。

I'm using jQuery 1.6.4 and signalR 1.0.0-alpha2. The client side connected and disconnected methods are not being executed. And if I put a breakpoint in OnConnected or OnDisconnected, the breakpoints don't hit.

正在取得的连接,我呼吁TestMethod的确定,我得到一个从的ConnectionId signalR的谈判回电。

The connection is being made as my TestMethod calls ok and I'm getting a connectionId back from signalR's negotiate call.

我敢肯定,我失去了一些东西简单。

I'm sure I'm missing something simple.

先谢谢了。

推荐答案

您的客户端处理程序可能应该是这样的:

Your client handlers should probably look like this:

$.connection.onlineHub.client.connected = function(){...}

这篇关于SignalR OnConnected和OnDisconnected不点火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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