SignalR-samples icon indicating copy to clipboard operation
SignalR-samples copied to clipboard

how to create hubconnection with websocket for android client

Open hirenpatel868 opened this issue 6 years ago • 21 comments
trafficstars

hirenpatel868 avatar Dec 27 '18 13:12 hirenpatel868

Have you taken a look at https://docs.microsoft.com/en-us/aspnet/core/signalr/java-client?view=aspnetcore-2.2?

BrennanConroy avatar Jan 02 '19 17:01 BrennanConroy

Yes...but its asp.net core..my backend signalr is in asp.net....i used this asp.net core lib but failed to connect with signalr server

hirenpatel868 avatar Jan 02 '19 17:01 hirenpatel868

Those are not compatible. You have to use either asp.net server with asp.net client, or asp.net core signalr with asp.net core client. You can't mix them.

BrennanConroy avatar Jan 02 '19 17:01 BrennanConroy

Do you any signarl java client which support websocket transport with asp.net signalr server .?

hirenpatel868 avatar Jan 03 '19 03:01 hirenpatel868

There is https://github.com/SignalR/java-client however it is no longer maintained.

BrennanConroy avatar Jan 03 '19 16:01 BrennanConroy

Thnk you for you fast replay....i tried to generate jar files using this but i am not able to generate jar files..can you help me to build jar files using this java client..

hirenpatel868 avatar Jan 03 '19 16:01 hirenpatel868

I've never used that client before so I have no idea how to use it sorry.

BrennanConroy avatar Jan 03 '19 18:01 BrennanConroy

The client at https://github.com/SignalR/java-client has been deprecated. While SignalR on asp.net is still supported, just that specific client is no longer supported. 🙁

mikaelm12 avatar Jan 03 '19 19:01 mikaelm12

dear all my backend signalr is in asp.net core 2.1 , but the java client is available in aps.net core 2.2 and later...... Who has a solution to tell me? thank u. My English is terrible. sorry.

gxh-apologize avatar Apr 18 '19 06:04 gxh-apologize

Have you tried and run into issues using the SignalR Java client with your AspNetCore SignalR 2.1 app? It should work.

mikaelm12 avatar Apr 18 '19 06:04 mikaelm12

@gxh-apologize i think so it should work..there is no version compatibility issue with .core signalr ....but if you have .net signalr as backend and you are using .net core signalr at front end then you faced version compatibility issues..

hirenpatel868 avatar Apr 18 '19 06:04 hirenpatel868

Have you tried and run into issues using the SignalR Java client with your AspNetCore SignalR 2.1 app? It should work.

04-18 14:09:14.827 3655-3724/cn.gxh.view E/OkHttpWebSocketWrapper: WebSocket closed from an error: Expected 'Connection' header value 'Upgrade' but was 'null'. 04-18 14:09:14.828 3655-3724/cn.gxh.view I/WebSocketTransport: WebSocket connection stopping with code null and reason 'Expected 'Connection' header value 'Upgrade' but was 'null''. 04-18 14:09:14.828 3655-3724/cn.gxh.view E/c*.m*.s*.HubConnection: HubConnection disconnected with an error Expected 'Connection' header value 'Upgrade' but was 'null'.

--------- beginning of crash

04-18 14:09:14.831 3655-3724/cn.gxh.view E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher Process: cn.gxh.view, PID: 3655 java.lang.NullPointerException: Attempt to invoke virtual method 'void com.microsoft.signalr.HubConnection$ConnectionState.cancelOutstandingInvocations(java.lang.Exception)' on a null object reference at com.microsoft.signalr.HubConnection.stopConnection(HubConnection.java:431) at com.microsoft.signalr.HubConnection.lambda$start$6$HubConnection(HubConnection.java:301) at com.microsoft.signalr.HubConnection$$Lambda$19.invoke(Unknown Source) at com.microsoft.signalr.WebSocketTransport.onClose(WebSocketTransport.java:93) at com.microsoft.signalr.WebSocketTransport.lambda$start$1$WebSocketTransport(WebSocketTransport.java:56) at com.microsoft.signalr.WebSocketTransport$$Lambda$1.invoke(Unknown Source) at com.microsoft.signalr.OkHttpWebSocketWrapper$SignalRWebSocketListener.onFailure(OkHttpWebSocketWrapper.java:98) at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:570) at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:197) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)

gxh-apologize avatar Apr 18 '19 06:04 gxh-apologize

@mikaelm12 there is not connectionStateChanged listener..how to get connection state changed event ... i also facing issue of signalr disconnection at certain interval..so is there any specific setting we have to apply at both ends..? how many users at a time can connect with one signalr backend..is there any limitations for numbers of users signalr can handle ?

hirenpatel868 avatar Apr 18 '19 06:04 hirenpatel868

@gxh-apologize What version of the SignalR Java client are you using? And do you have websockets enabled on your back end site? Cloud providers usually have it off by default and have a toggle to turn websocket support on.

mikaelm12 avatar Apr 18 '19 06:04 mikaelm12

there is not connectionStateChanged listener..how to get connection state changed event

@hirenpatel868 In the current version of the Java client we only have two states. Connected and Disconnected. So the onClosed callback would be what you're looking for since there is no auto reconnect (we're planning to add support for that in 3.0).

mikaelm12 avatar Apr 18 '19 06:04 mikaelm12

@mikaelm12 ` implementation 'com.microsoft.signalr:signalr:1.0.0 HubConnection hubConnection; public void signalr() { hubConnection = HubConnectionBuilder.create(url) .build(); hubConnection.on("Send", new Action() { @Override public void invoke() { Logger.d("gxh", "......"); } });

    new HubConnectionTask().execute(hubConnection);

}

class HubConnectionTask extends AsyncTask<HubConnection, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Void doInBackground(HubConnection... hubConnections) {
        HubConnection hubConnection = hubConnections[0];
        hubConnection.start().blockingAwait();
        return null;
    }
}

` My code refers to demo.The server is not my responsibility.I need to ask them .thank u.

gxh-apologize avatar Apr 18 '19 06:04 gxh-apologize

@mikaelm12...ok i will check it out..but what about facing issue of signalr disconnection at certain interval..so is there any specific setting we have to apply at both ends..? how many users at a time can connect with one signalr backend..is there any limitations for numbers of users signalr can handle ?

hirenpatel868 avatar Apr 18 '19 06:04 hirenpatel868

@gxh-apologize One thing you could do is upgrade to the 3.0.0-preview3-19153-02 version. Note that it is a preview version though. But with this you can set the transport to LongPolling and see if you are able to successfully connect.

mikaelm12 avatar Apr 18 '19 20:04 mikaelm12

You would set LongPolling like this

HubConnection hubConnection = HubConnectionBuilder
    .create("http://example.com")
    .withTransport(TransportEnum.LONG_POLLING)
    .build();

mikaelm12 avatar Apr 18 '19 20:04 mikaelm12

@hirenpatel868

but what about facing issue of signalr disconnection at certain interval

Can you elaborate on this? This is not something you should be seeing normally without any special configuration.

how many users at a time can connect with one signalr backend..is there any limitations for numbers of users signalr can handle ?

This is a very application/machine specific question.

mikaelm12 avatar Apr 18 '19 20:04 mikaelm12

@mikaelm12 I can connect to my server with 3.0.0-preview3-19153-02 version . thank u .

gxh-apologize avatar Apr 19 '19 02:04 gxh-apologize