aspnet / SignalR-samples

Samples for ASP.NET Core SignalR
753 stars 398 forks source link

how to create hubconnection with websocket for android client #64

Open hirenpatel868 opened 5 years ago

BrennanConroy commented 5 years ago

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

hirenpatel868 commented 5 years ago

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

BrennanConroy commented 5 years ago

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.

hirenpatel868 commented 5 years ago

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

BrennanConroy commented 5 years ago

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

hirenpatel868 commented 5 years ago

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..

BrennanConroy commented 5 years ago

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

mikaelm12 commented 5 years ago

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. 🙁

gxh-apologize commented 5 years ago

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.

mikaelm12 commented 5 years ago

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

hirenpatel868 commented 5 years ago

@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..

gxh-apologize commented 5 years ago

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)

hirenpatel868 commented 5 years ago

@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 ?

mikaelm12 commented 5 years ago

@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 commented 5 years ago

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 onClosedcallback would be what you're looking for since there is no auto reconnect (we're planning to add support for that in 3.0).

gxh-apologize commented 5 years ago

@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.

hirenpatel868 commented 5 years ago

@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 ?

mikaelm12 commented 5 years ago

@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 commented 5 years ago

You would set LongPolling like this

HubConnection hubConnection = HubConnectionBuilder
    .create("http://example.com")
    .withTransport(TransportEnum.LONG_POLLING)
    .build();
mikaelm12 commented 5 years ago

@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.

gxh-apologize commented 5 years ago

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