signalr - Setting up Signal R in Android: Crash/Hung Issue -
i followed this tutorial set .net backend android app implement signal r. set signalr self-hosted backend.
here's backend code in console project:
namespace signalrselfhost { class program { static void main(string[] args) { // *only* bind localhost, if want bind addresses // use http://*:8080 bind addresses. // see http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx // more information. string url = "http://localhost:8080"; using (webapp.start(url)) { console.writeline("server running on {0}", url); console.readline(); } } } class startup { public void configuration(iappbuilder app) { app.usecors(corsoptions.allowall); app.mapsignalr(); } } public class messagehub : hub { public static event action<string, string> messagereceived = delegate { }; public void sendmessage(string name, string message) { messagereceived(name, message); } } public class customtype { public string name; public int id; } }
my android code:
handler handler; textview statusfield; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main2); handler = new handler(); statusfield = (textview) findviewbyid(r.id.statusfield); platform.loadplatformcomponent(new androidplatformcomponent()); // change ip address , matching port of signalr server. string host = "http://192.168.1.5:8080/"; hubconnection connection = new hubconnection( host ); hubproxy hub = connection.createhubproxy( "messagehub" ); clienttransport transport = new serversenteventstransport(connection.getlogger()); signalrfuture<void> awaitconnection = connection.start(transport); try { awaitconnection.get(); } catch (interruptedexception e) { log.d("check", e.tostring()); e.printstacktrace(); } catch (executionexception e) { log.d("check", e.tostring()); e.printstacktrace(); } hub.subscribe(this); try { hub.invoke( "sendmessage", "client", "hello world!" ).get(); hub.invoke( "sendcustomtype", new customtype() {{ name = "universe"; id = 42; }} ).get(); } catch (interruptedexception e) { // handle ... } catch (executionexception e) { // handle ... } } public void updatestatus(string status) { final string fstatus = status; handler.post(new runnable() { @override public void run() { statusfield.settext(fstatus); } }); } public class customtype { public string name; public int id; }
however, end screen hangs , displays nothing , app stops responding. android logger displays following error:
java.util.concurrent.executionexception: java.net.connectexception: failed connect localhost/127.0.0.1 (port 80) after 15000ms: isconnected failed: econnrefused (connection refused)
is code correct , have followed guide properly? it's straight forward guide issue comes up. can out?
edit:
this similar question, in fact describes same issue. didn't me good. if notice android code, i've made changes proposed in question. still didn't rectify issue.
stacktrace
java.util.concurrent.executionexception: java.net.sockettimeoutexception: failed connect / 192.168.1.5(port 8080) after 15000ms @ microsoft.aspnet.signalr.client.signalrfuture.get(signalrfuture.java: 112) @ microsoft.aspnet.signalr.client.signalrfuture.get(signalrfuture.java: 102) @ com.example.dinuka.signalrtest.main2activity.oncreate(main2activity.java: 40) @ android.app.activity.performcreate(activity.java: 6289) @ android.app.instrumentation.callactivityoncreate(instrumentation.java: 1119) @ android.app.activitythread.performlaunchactivity(activitythread.java: 2655) @ android.app.activitythread.handlelaunchactivity(activitythread.java: 2767) @ android.app.activitythread.access$900(activitythread.java: 177) @ android.app.activitythread$h.handlemessage(activitythread.java: 1449) @ android.os.handler.dispatchmessage(handler.java: 102) @ android.os.looper.loop(looper.java: 145) @ android.app.activitythread.main(activitythread.java: 5951) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java: 372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java: 1400) @ com.android.internal.os.zygoteinit.main(zygoteinit.java: 1195) caused by: java.net.sockettimeoutexception: failed connect / 192.168.1.5(port 8080) after 15000ms @ libcore.io.iobridge.connecterrno(iobridge.java: 169) @ libcore.io.iobridge.connect(iobridge.java: 122) @ java.net.plainsocketimpl.connect(plainsocketimpl.java: 183) @ java.net.plainsocketimpl.connect(plainsocketimpl.java: 456) @ java.net.socket.connect(socket.java: 882) @ com.android.okhttp.internal.platform.connectsocket(platform.java: 139) @ com.android.okhttp.connection.connect(connection.java: 1194) @ com.android.okhttp.internal.http.httpengine.connect(httpengine.java: 392) @ com.android.okhttp.internal.http.httpengine.sendrequest(httpengine.java: 295) @ com.android.okhttp.internal.http.httpurlconnectionimpl.execute(httpurlconnectionimpl.java: 373) @ com.android.okhttp.internal.http.httpurlconnectionimpl.getresponse(httpurlconnectionimpl.java: 323) @ com.android.okhttp.internal.http.httpurlconnectionimpl.getresponsecode(httpurlconnectionimpl.java: 491) @ microsoft.aspnet.signalr.client.http.java.networkrunnable.run(networkrunnable.java: 72) @ java.lang.thread.run(thread.java: 818)
i had similar issue few days ago , github issue helped: https://github.com/signalr/java-client/issues/63
basically did modify websockettransport.java in signalr-client-sdk project. replace:
uri = new uri(url);
with
uri = new uri(url.replace("http://", "ws://"));
around line 86 in source code.
i can connect , send message , recieve raw data cannot subscribe events...
hope helps passed problem.
Comments
Post a Comment