SignalR和标签,窗口,克隆的框架? [英] SignalR and Tabs , windows , cloned frames?

查看:125
本文介绍了SignalR和标签,窗口,克隆的框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的应用程序,它从客户端接受短信和回复以特定连接:嘿,我收到了你的信息,而除此之外,广播消息给所有其他<。 / p>

code海贼王:

  1保护覆盖任务OnConnected(IRequest请求字符串的ConnectionId)
 2 {
 3回Connection.Send(ConnectionId之外,欢迎光临!);
 4}
 五
 6保护覆盖任务OnReceived(IRequest请求字符串的ConnectionId,字符串数据)
 7 {
 8 Connection.Send(ConnectionId之外,连线+ +的ConnectionId我收到你的信息+数据);
 9返回Connection.Bro​​adcast(数据);
 10}

一切都OK。

<大骨节病>问题1
请问连接ID 是唯一的初始化100%?怎么样,如果我克隆一个浏览器标签?或克隆的iFrame?从我的测试中它是独一无二的。但我需要确认一下。

<大骨节病>问题2

在看线#8,我写不出返回Connection.Send ,因为其他行会不会被执行。但我认为,这样一来,我就失去了TASK&LT;>返回值。如果我需要什么呢?

OnReceived 返回工作,但当前只返回 Connection.Bro​​adcast(数据); 的任务(如我说 - 我失去了生产线的#8的任务返回的对象),我怕IM在这里做得不对。也许我不是?

在谁应用循环使用此任务的结果呢?


解决方案

1:是连接ID始终是唯一的结果
2 Connection.Send不会返回其经由客户机返回一个值,SignalR不支持。不过,如果你有兴趣只是等待它和获取你可以做的Connection.Send .Wait()(该任务的状态),也可以ContinueWith,

又名

  Connection.Send(...)等待()。 //如果有错误,这将抛出
返回Connection.Bro​​adcast(数据);

  Connection.Send(....)ContinueWith(任务=&GT; {
        如果(!task.IsFaulted)
        {
            //任务成功运行
        }
        其他
        {
            //出了错发送时,你可以从任务异常
        }
    });
    返回Connection.Bro​​adcast(数据);

I created a simple app which accept a text message from a client and reply to that specific connection : "Hey I got your message" , and besides that , broadcast the message to all others.

Piece of code :

 1     protected override Task OnConnected(IRequest request, string connectionId)
 2       {
 3                return Connection.Send(connectionId, "Welcome!");
 4       }
 5        
 6     protected override Task OnReceived(IRequest request, string connectionId, string data)
 7       {
 8         Connection.Send(connectionId, "Connection " + connectionId + " I got your message " + data);
 9         return Connection.Broadcast(data);
 10      }

All is OK.

Question #1 Does Connection ID is 100% unique to the initializer ? what about if I clone a browser tab ?, or cloned Iframe ? from my testing it is unique. but I need to make sure.

Question #2

looking at line #8 , I couldn't write return Connection.Send because the other line won't be executed . however I think , that way , I will lose the TASK<> return value . what if i'll need it ?

OnReceived returns a Task but currently it returns just the Connection.Broadcast(data);'s task and (as I was saying - I'm losing line's #8 task return object.)Im afraid im doing something wrong here. or maybe I'm not ?

Who uses this task result in the app cycle anyway?

解决方案

1: Yes connection ID is always unique
2 The Connection.Send will not return a value that is returned via the client, SignalR does not support that. However, if you're interested in just waiting for it and getting the status of the task you can do .Wait() on the Connection.Send() or you can ContinueWith,

Aka

Connection.Send(...).Wait(); // If there's an error this will throw
return Connection.Broadcast(data);

OR

  Connection.Send(....).ContinueWith(task => {
        if(!task.IsFaulted) 
        {
            // Task ran successfully    
        }
        else 
        {
            // Something went wrong when sending, you can get the exception from the task
        }
    });
    return Connection.Broadcast(data);

这篇关于SignalR和标签,窗口,克隆的框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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