SignalR / java-client

OBSOLETE - see readme
Other
317 stars 245 forks source link

Android - SignalR - not receiving message from server #120

Closed vandanabpatel closed 7 years ago

vandanabpatel commented 7 years ago

HubConnection mHubConnection; HubProxy mHubProxy;

try { Platform.loadPlatformComponent(new AndroidPlatformComponent()); mHubConnection = new HubConnection("http://differenzuat.com/SignalRChat/signalr/hubs"); mHubProxy = mHubConnection.createHubProxy("ChatHub"); ClientTransport transport = new ServerSentEventsTransport(mHubConnection.getLogger());

        mHubProxy.on("sendPrivateMessage",
                new SubscriptionHandler1<Object>() {
                    @Override
                    public void run(final Object result) {
                        Log.e(TAG, "Message Received :: ");
                        try {
                            JSONObject json = decodeResult(result);
                            Log.e(TAG, "Message Received :: " + json.toString());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, Object.class);

        SignalRFuture<Void> signalRFuture = mHubConnection.start();
        signalRFuture.get();

        mHubConnection.error(new ErrorCallback() {
            @Override
            public void onError(Throwable e) {
                Log.e(TAG, "mHubConnection.error :: " + e.toString());
                e.printStackTrace();
            }
        });

        // Subscribe to the connected event
        mHubConnection.connected(new Runnable() {
            @Override
            public void run() {
                Log.e(TAG, "CONNECTED");
            }
        });

    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

// here, i am calling invoke method to send message mHubProxy.invoke("SendPrivateMessage", "30", "31", "test message", "");

public static JSONObject decodeResult(Object result) throws JSONException { if (result == null) return null; Gson gson = new GsonBuilder().serializeNulls().create();//Fix the missing null attributes problem return new JSONObject(gson.toJson(result)); }

============================== i am getting following error log

E/ChatActivity: mHubConnection.error :: java.lang.RuntimeException: The handler has 1 parameters, but there are 7 values. W/System.err: java.lang.RuntimeException: The handler has 1 parameters, but there are 7 values. W/System.err: at microsoft.aspnet.signalr.client.hubs.HubProxy$5.run(HubProxy.java:332) W/System.err: at microsoft.aspnet.signalr.client.hubs.HubProxy$5.run(HubProxy.java:1) W/System.err: at microsoft.aspnet.signalr.client.hubs.Subscription.onReceived(Subscription.java:31) W/System.err: at microsoft.aspnet.signalr.client.hubs.HubProxy.invokeEvent(HubProxy.java:308) W/System.err: at microsoft.aspnet.signalr.client.hubs.HubConnection.onReceived(HubConnection.java:118) W/System.err: at microsoft.aspnet.signalr.client.transport.TransportHelper.processReceivedData(TransportHelper.java:96) W/System.err: at microsoft.aspnet.signalr.client.Connection.processReceivedData(Connection.java:733) W/System.err: at microsoft.aspnet.signalr.client.Connection.access$0(Connection.java:728) W/System.err: at microsoft.aspnet.signalr.client.Connection$10.onData(Connection.java:671) W/System.err: at microsoft.aspnet.signalr.client.transport.ServerSentEventsTransport$1.onResponse(ServerSentEventsTransport.java:104) W/System.err: at microsoft.aspnet.signalr.client.http.java.NetworkRunnable.run(NetworkRunnable.java:82) W/System.err: at java.lang.Thread.run(Thread.java:761)

moozzyk commented 7 years ago

I believe the exception says that your callback has just one parameter but the server is trying to invoke it with 7 arguments so there is a mismatch.

vandanabpatel commented 7 years ago

i have resolved above issues thank you.