简体   繁体   中英

How to connect to SignalR on Android

Is there some alternative way to connect to backend with SignalR without using specific library like https://github.com/SignalR/java-client . As I can see it's not updated for a while and has some major issues.

I'm not familiar with SignalR but is it possible to connect to .net SignalR with other java websockets libraries like AsyncHttpClient or SignalR and WebSocket are completely different protocols?

There was such questions but not sure is it still up to date because last answer was few years ago Java client to connect to SignalR?

I'm work with SignalR many times, and it is no other ways use alternative libraries. Only official SignalR library. You can make wrapper around this library, and fix some issues. That it;(

Package:

    //microsoft signalR
    implementation 'com.microsoft.signalr:signalr:3.0.0'
    implementation group: 'org.slf4j', name: 'slf4j-android', version: '1.7.7'

Code:

 HubConnection hub;
 hub=  HubConnectionBuilder.create("http://yoursite.com/hub")
                    .withTransport(TransportEnum.LONG_POLLING)
                    .build();
 hub.start();

 //retrieve response
 hub.on("MathodeName", (param1, param2) -> {
     // your method or statement
 },String.class, String.class);

 //send response
 hub.send("AcceptKitchen", param1, param2);

 //to stop connection
 hub.stop();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM