We have a SignalR hub. The following jQuery code connects and properly processes SignalR client "call" events successfully on cordova.
var connectionURL = "https://SOMEURL.azurewebsites.net/message";
connection = $.connection(connectionURL);
connection.start().done(function () {
console.log("Connected to hub again");
});
connection.disconnected(function () {
setTimeout(function () {
connection.start().done(function () {
console.log("Disconnected and Connected to hub again");
});
}, 5000);
});
connection.stateChanged(function (change) {
if (change.newState == $.signalR.connectionState.reconnecting) {
}
else if (change.newState == $.signalR.connectionState.connected) {
}
else if (change.newState == $.signalR.connectionState.disconnected) {
}// else if
});
connection.received(function (data) {
connectId = connection.id + "";
console.log("onDeviceReady run");
// call the function to parse the data
if (data.PayloadType == "Dispatch") {
dataDispatch(data);
}
if (data.PayloadType == "ConnectionAcknowledge") {
sendConnectionAcknowledge(data);
}
});
However when I try to emulate this code in java android using the SignalR Java Client, I get a lot of log output (tonnes), and no connection ever finishes. it gets as far as the debug at line awaitConnection.get();
and never prints the second line of debug, instead it prints endless (thousands) of lines of semi gibberish (it's not piping, it's like it's some sort of "SSL handshake" but it's not doing anything but logging the same thing repeatedly, very odd) anyway it never runs the 2nd line of "my" debug
package com.some.thing;
import android.util.Log;
import java.util.concurrent.ExecutionException;
import microsoft.aspnet.signalr.client.Platform;
import microsoft.aspnet.signalr.client.SignalRFuture;
import microsoft.aspnet.signalr.client.http.android.AndroidPlatformComponent;
import microsoft.aspnet.signalr.client.hubs.HubConnection;
import microsoft.aspnet.signalr.client.hubs.HubProxy;
import microsoft.aspnet.signalr.client.hubs.SubscriptionHandler1;
public class SignalRClient {
public static void startConnection() {
Platform.loadPlatformComponent(new AndroidPlatformComponent());
String host = "https://SOMEURL.azurewebsites.net/message";
HubConnection connection = new HubConnection(host);
HubProxy hub = connection.createHubProxy( "IDoNoHaveThisNorKnowIt" );
SignalRFuture<Void> awaitConnection = connection.start();
try {
Log.v("CONANSignalR :=", "CONNECTING");
awaitConnection.get();
Log.v("CONANSignalR :=", "CONNECTED");
} catch (InterruptedException e) {
// Handle ...
} catch (ExecutionException e) {
// Handle ...
}
hub.on("IDoNotKnowThisEither", new SubscriptionHandler1<String>(){
@Override
public void run( String status ){
Log.v("CONANDispatch :=", status);
}
}, String.class);
}
}
Can anyone help me translate the working, jQuery SignalR client code into usable java client code? I don't have any information on the hub so I cannot know the proxy or the function names, I'd like to see everything (like the jQuery).
EDIT
To test things, I have altered my original jquery code it use to say
console.log("onDeviceReady run");
now it says
console.log("SignalR Raw Data:" + JSON.stringify(data));
when I do this this is what the jquery returns
SignalR Raw Data:{"ConnectionId":"9c4b4ba5-cb6e-4dcb-8df9-069cbf749873","OrderId":null,"SenderId":null,"PayloadType":"ConnectionAck","Message":"Welcome, you are connected to the Hub!","Payload":null,"Initiator":"HUB","Version":null}
however none of this appears inside the java equivalent
connection.received(new MessageReceivedHandler() {
@Override
public void onMessageReceived(JsonElement json) {
System.out.println("RAW received message: " + json.toString());
// ADD HANDLING OF RECEIVED IN HERE
}
});
i.e. the text "RAW received message:" doesn't appear at all