0

I have found SDK of Signalr for Android: https://github.com/SignalR/java-client. My code is working fine when web app is hosted on IIS but when I deploy on Azure, it's not able to connect; it waits forever

While my javascript client code is working fine. I follow following to deploy my web app: http://www.asp.net/signalr/overview/deployment/using-signalr-with-azure-web-sites

Following log I received

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/>
Deepak
  • 756
  • 4
  • 10
  • IMO, basic source code is good enough :), pls take a look at http://stackoverflow.com/questions/32573823/how-to-use-signalr-in-android/32574829#32574829 – BNK Dec 05 '15 at 05:55
  • I have implemented same method, and able to use it from local IIS, but when I upload my web solution on Azure, and try to connect from android, it doesn't respond, it wait always – Deepak Dec 05 '15 at 05:58
  • You question ask about Signalr for Android, however your comment about Asp.Net SignalR, I haven't tried using Azure. – BNK Dec 05 '15 at 06:00
  • I am able to use it from javascript client, I have issue when I connect it from andriod.. please see my updated question, I mention my log output.. it doesn't proceed after 'Getting connection data: [{"name":"myhub"}]' – Deepak Dec 05 '15 at 06:04
  • your Android source comes from https://github.com/SignalR/java-client/tree/master/signalr-client-test-integration-android/src/main/java/microsoft/aspnet/signalr/client/test/integration/android ? – BNK Dec 05 '15 at 06:07
  • yes kind of I modified it as per my need, if you want I can share code... – Deepak Dec 05 '15 at 06:07
  • IMO, you can refer to my sample project at https://github.com/ngocchung/SimpleSignalRClient, which connects to server-side I got from http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr – BNK Dec 05 '15 at 06:08
  • I did same, but not able to proceed further.. it wait last forever. please see my code https://drive.google.com/file/d/0B4e_lmhXq0oaRG42LTNnVTl3Snc/view?usp=sharing – Deepak Dec 05 '15 at 06:10
  • Try `mAwaitConnection = mConnection.start(mTransport);` instead of `awaitConnection = connection.start();` Moreover, in my sample project, I don't use `awaitConnection.done` – BNK Dec 05 '15 at 06:21
  • 1
    thanks... it worked :) :) – Deepak Dec 05 '15 at 06:34
  • Glad to hear that, happy coding :) – BNK Dec 05 '15 at 06:36

2 Answers2

2

Based on @BNK's comments & my understanding, I post the answer for people have the same issue.

I reviewed the code Connection.java (https://github.com/SignalR/java-client/blob/master/signalr-client-sdk/src/main/java/microsoft/aspnet/signalr/client/Connection.java) that has two functions called start. The code of function start with no argument below use the AutomaticTransport as the default ClientTransport.

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

And I continued to review the code AutomaticTransport.java (https://github.com/SignalR/java-client/blob/master/signalr-client-sdk/src/main/java/microsoft/aspnet/signalr/client/transport/AutomaticTransport.java). It try to select the one of the three ClientTransport in the function initialize that contains WebSocketTransport, ServerSentEventsTransport & LongPollingTransport, please see below.

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

The reason of the issue might be the server using SignalR on Azure that not implement for supporting the three transport of AutomaticaTransport.

So using the function public SignalRFuture<Void> start(final ClientTransport transport) of Class Connection to select a transport suppored by the server-side manually to solve the issue.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
-1

SignalR depends on WebSockets. To use SignalR on Azure Web Apps you have to enable WebSockets for your site.

To enable WebSockets go to your site in https://manage.windowsazure.com->Configure->WebSockets->Set to "On"

Zain Rizvi
  • 23,586
  • 22
  • 91
  • 133