java - SignalR Android access localhost -
for reason cannot make make android app connect server (on localhost)
the problem (probably) not in code,the exact same code runs fine in simple java application
i invalidhttpstatuscodeexception
bad request - invalid hostname http error 400. request hostname invalid.
i tried using emulator ,genymotion(i changed ip http://192.168.56.1... )
java.util.concurrent.executionexception: microsoft.aspnet.signalr.client.transport.negotiationexception: there problem in negotiation server
i exception in httpclientransport.java ,line 76
@override public signalrfuture<negotiationresponse> negotiate(final connectionbase connection) { log("start negotiation server", loglevel.information); string url = connection.geturl() + "negotiate" + transporthelper.getnegotiatequerystring(connection); request = new request(constants.http_get); get.seturl(url); get.setverb(constants.http_get); connection.preparerequest(get); final signalrfuture<negotiationresponse> negotiationfuture = new signalrfuture<negotiationresponse>(); log("execute request", loglevel.verbose); httpconnectionfuture connectionfuture = mhttpconnection.execute(get, new responsecallback() { public void onresponse(response response) { try { log("response received", loglevel.verbose); throwoninvalidstatuscode(response); log("read response data end", loglevel.verbose); string negotiationcontent = response.readtoend(); log("trigger onsuccess negotiation data: " + negotiationcontent, loglevel.verbose); negotiationfuture.setresult(new negotiationresponse(negotiationcontent, connection.getjsonparser())); } catch (throwable e) { log(e); negotiationfuture.triggererror(new negotiationexception("there problem in negotiation server", e)); } } }); futurehelper.copyhandlers(connectionfuture, negotiationfuture); return negotiationfuture; }
if make request browser don't error
the response is
{"url":"/signalr/signalr","connectiontoken":"aqaaancmnd8bfderjhoawe/cl+sbaaaaiayx1zrb/e6bvu/+2lte0aaaaaacaaaaaaadzgaawaaaabaaaaa29atq2tga6k2br6mj5efoaaaaaasaaacgaaaaeaaaakhfvuynaigej/hee3xk4faoaaaacmvl4wixdw9x7qc0dfxatded/ggdt9wget+35bqhvjfvda6jgagbehqaaadadg/ev9sxe+bwyfgk10cp+omcyq==","connectionid":"982a12db-e4c8-4234-894a-3d1648e662d5","keepalivetimeout":20.0,"disconnecttimeout":30.0,"trywebsockets":false,"protocolversion":"1.3","transportconnecttimeout":5.0,"longpolldelay":0.0}
in both cases can access other services on server problem related signalr
here entire code
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.transport.serversenteventstransport; import android.os.asynctask; public class mytask extends asynctask<string, string, string> { private string username ="androiduser"; private microsoft.aspnet.signalr.client.hubs.hubproxy hubproxy; //string serveruri = "http://192.168.56.1:3227/signalr"; string serveruri = "http://10.0.2.2:3227/signalr"; private hubconnection connection ; signalrfuture<void> con; @override protected string doinbackground(string... params) { androidplatformcomponent com=new androidplatformcomponent(); platform.loadplatformcomponent(com); connection = new hubconnection(serveruri); hubproxy = connection.createhubproxy("myhub"); try { con =connection.start(new serversenteventstransport(connection.getlogger())); //or longpollingtransport con.get(); } catch (executionexception e) { e.printstacktrace(); } return "blabla"; } }
sorry long post wanted give details have
when starting server using this:
http://localhost:3227
changed to
http://192.168.56.1:3227
and works...
Comments
Post a Comment