I am trying to connect from android application with .NET webservice. I am using github.com/SignalR/java-client. I have almost no experience with Android and I cannot find solution to my problem. I tried to use these sample: github.com/SignalR/java-samples for implementing android client. In MainActivity.java I have method
public void buttonClick(View v)
{
HubConnection conn = new HubConnection("http://192.168.132.28:9000");
// Create the hub proxy
HubProxy proxy = conn.createHubProxy("HubClient");
proxy.subscribe(new Object() {
@SuppressWarnings("unused")
public void messageReceived(String name, String message) {
System.out.println(name + ": " + message);
}
});
// Subscribe to the error event
conn.error(new ErrorCallback() {
@Override
public void onError(Throwable error) {
error.printStackTrace();
}
});
// Subscribe to the connected event
conn.connected(new Runnable() {
@Override
public void run() {
System.out.println("CONNECTED");
}
});
// Subscribe to the closed event
conn.closed(new Runnable() {
@Override
public void run() {
System.out.println("DISCONNECTED");
}
});
// Start the connection
conn.start()
.done(new Action<Void>() {
@Override
public void run(Void obj) throws Exception {
System.out.println("Done Connecting!");
}
});
// Subscribe to the received event
conn.received(new MessageReceivedHandler() {
@Override
public void onMessageReceived(JsonElement json) {
System.out.println("RAW received message: " + json.toString());
}
});
// Read lines and send them as messages.
Scanner inputReader = new Scanner(System.in);
String line = inputReader.nextLine();
while (!"exit".equals(line)) {
proxy.invoke("send", "Console", line).done(new Action<Void>() {
@Override
public void run(Void obj) throws Exception {
System.out.println("SENT!");
}
});
line = inputReader.next();
}
inputReader.close();
conn.stop();
}
This method is invoked when button is pressed. But when I press the button I get an exception microsoft.aspnet.signalr.client.transport.NegotiationException: There was a problem in the negotiation with the server I use this webservice for testing. Here is full log from logcat (after pressing button). I disabled my firewall for testing. I tried to connect to server on my local computer and later on remote server. In both cases I have the same exception. I appreciate any suggestions.
P.S. I apologize for not using https in links to github, but new users are only allowed to create 2 links.
0 comments:
Post a Comment