当 Web 应用程序位于 Azure 上时,Signalr (Android) 不起作用



我找到了 Signalr for Android 的 SDK:https://github.com/SignalR/java-client。当 Web 应用程序托管在 IIS 上时,我的代码工作正常,但当我在 Azure 上部署时,它无法连接;它永远等待

虽然我的 JavaScript 客户端代码工作正常。我按照以下内容部署我的 Web 应用程序:http://www.asp.net/signalr/overview/deployment/using-signalr-with-azure-web-sites

我收到的以下日志

AutomaticTransport - Response received<br/>
AutomaticTransport - Read response data to the end<br/>
AutomaticTransport - Trigger onSuccess with negotiation data: {"Url":"/signalr","ConnectionToken":"4GGnSKxMOsuP6jkG1det5Z3Ch073H6ixe3Ium6k69k/RAM/x2KJkHP03XkNnPx56EatX8qxDmSOASS7HGKm5UJtsTqCP71YVJ05vLYrAT4pLYzecAwxziEUotCyVUpOc","ConnectionId":"28e1bb42-f03d-42b9-a874-171be7531eef","KeepAliveTimeout":20.0,"DisconnectTimeout":30.0,"ConnectionTimeout":110.0,"TryWebSockets":true,"ProtocolVersion":"1.3","TransportConnectTimeout":5.0,"LongPollDelay":0.0}<br/>
HubConnection - Negotiation completed<br/>
HubConnection - ConnectionId: 28e1bb42-f03d-42b9-a874-171be7531eef<br/>
HubConnection - ConnectionToken: 4GGnSKxMOsuP6jkG1det5Z3Ch073H6ixe3Ium6k69k/RAM/x2KJkHP03XkNnPx56EatX8qxDmSOASS7HGKm5UJtsTqCP71YVJ05vLYrAT4pLYzecAwxziEUotCyVUpOc<br/>
HubConnection - Keep alive timeout: 20.0<br/>
HubConnection - Entered startLock in startTransport<br/>
HubConnection - Starting the transport<br/>
HubConnection - Starting transport for InitialConnection<br/>
HubConnection - Getting connection data: [{"name":"myhub"}]<br/>
HubConnection - Getting connection data: [{"name":"myhub"}]<br/>

根据@BNK的评论和我的理解,我发布了人们有相同问题的答案。

我回顾了代码Connection.java(https://github.com/SignalR/java-client/blob/master/signalr-client-sdk/src/main/java/microsoft/aspnet/signalr/client/Connection.java(,它有两个称为start的函数。下面没有参数的函数start的代码使用 AutomaticTransport 作为默认ClientTransport

public SignalRFuture<Void> start() {
    return start(new AutomaticTransport(mLogger));
}

我继续查看代码AutomaticTransport.java(https://github.com/SignalR/java-client/blob/master/signalr-client-sdk/src/main/java/microsoft/aspnet/signalr/client/transport/AutomaticTransport.java(。它尝试在包含WebSocketTransportServerSentEventsTransportLongPollingTransport的函数initialize中选择三种ClientTransport之一,请参见下文。

private void initialize(Logger logger) {
    mTransports = new ArrayList<ClientTransport>();
    mTransports.add(new WebsocketTransport(logger));
    mTransports.add(new ServerSentEventsTransport(logger));
    mTransports.add(new LongPollingTransport(logger));
}

问题的原因可能是在 Azure 上使用 SignalR 的服务器未实现支持三种传输AutomaticaTransport

因此,使用类Connection的函数public SignalRFuture<Void> start(final ClientTransport transport)手动选择服务器端支持的传输来解决问题。

SignalR 依赖于 WebSockets。 若要在 Azure Web 应用上使用 SignalR,必须为站点启用 WebSocket。

若要启用 WebSockets,请转到 https://manage.windowsazure.com->配置->WebSockets->设置为"开"中的站点

相关内容

  • 没有找到相关文章

最新更新