【问题标题】:SignalR messages are delayed on Windows Phone appSignalR 消息在 Windows Phone 应用程序上延迟
【发布时间】:2015-02-04 17:32:10
【问题描述】:

我正在使用 SignalR 在网站和 Windows Phone 应用程序(Windows Phone 8.0、silverlight)之间发送消息。

在 Windows 手机应用程序中,我使用 Nuget Microsoft.AspNet.SignalR.Client 的 SignalR 客户端,发送消息似乎可以正常工作,但接收消息需要几秒钟。

this.connection = new HubConnection("http://myapp.azurewebsites.net/");
this.theHub = connection.CreateHubProxy("myHub");
await connection.Start();
this.theHub.On<String>("message",
            string=>
                {
                    // Here I receive the message very late
                });

在 javascript 方面,消息到达时不会延迟。

在 Windows Phone 上有什么需要配置的吗?

【问题讨论】:

  • 没有什么特别需要为 Windows Phone 配置的。如果可以的话,我会启用日志记录“connection.logging = true;” ,并查看集线器在客户端做什么。
  • 尝试使用不同的传输方式(例如长轮询),看看是否有帮助。我想我看到了一个错误,即在手机上使用默认传输时消息会延迟几秒钟。
  • 是的,在启动连接时添加长轮询传输解决了这个问题。现在可以了 await connection.Start(new LongPollingTransport());

标签: c# windows-phone-8 windows-phone signalr


【解决方案1】:

我不得不使用长轮询传输,因为默认传输延迟了消息。

可以在启动连接时设置传输:

await connection.Start(new LongPollingTransport());

正如下面评论中所说,WebSocket 传输可能更好

await connection.Start (new WebSocketTransport());

【讨论】:

  • 可能WebSocket传输比较好,如果手动设置,会像LongPolling一样快。所以,试试这个:await connection.Start (new WebSocketTransport());
  • 我现在无法测试,但是根据 msdn,Windows Phone 不支持 WebSocket asp.net/signalr/overview/getting-started/supported-platforms
  • 我昨天试过了,感觉不错,不过你可以看看。用默认值(空)很慢。当我找到这个答案(LongPollingTransport)时,我尝试了它,并更改为 WebSocketTransport。两者都工作正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-11
  • 2015-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多