无法通过HubProxy.on方法在signalR客户端Android中获取数据

时间:2014-05-07 13:04:42

标签: signalr

我已经成功实现了android的signalR客户端,但我的问题是从服务器获取返回数据。我可以从侧面发送消息,当我正在播放时它正在其他客户端显示,但我没有收到消息。    任何人都可以通过hubproxy.on方法帮助我获取消息。

            String host = "serverlink";
    connection = new HubConnection(host);
    hub = connection.createHubProxy("myHub");
            hub.subscribe(MainActivity.this);

    hub.on("addChatMessage", new SubscriptionHandler() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            System.out.println("test");
        }
    });



    // connection.start();
    SignalRFuture<Void> awaitConnection = connection.start();
    try {
        awaitConnection.get();
    } catch (InterruptedException e) {
        System.out.println("<<<Exception>>>" + e.toString() + "<<<>>>"
                + e.getMessage());
    } catch (ExecutionException e) {
        System.out.println("<<<Exception>>>" + e.toString() + "<<<>>>"
                + e.getMessage());
    }



    joinButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                hub.invoke("InformUserName", joinEditText.getText().toString()).get();
            } catch (InterruptedException e) {
                System.out.println("<<<Exception>>>" + e.toString()
                        + "<<<>>>" + e.getMessage());
            } catch (ExecutionException e) {
                System.out.println("<<<Exception>>>" + e.toString()
                        + "<<<>>>" + e.getMessage());
            }
        }
    });

    sendButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                hub.invoke("Send", joinEditText.getText().toString(), messEditText.getText().toString()).get();
            } catch (InterruptedException e) {
                System.out.println("<<<Exception>>>" + e.toString() + "<<<>>>"
                        + e.getMessage());
            } catch (ExecutionException e) {
                System.out.println("<<<Exception>>>" + e.toString() + "<<<>>>"
                        + e.getMessage());
            }
        }
    });

hub.on未调用我如何初始化subcriptionhandler

0 个答案:

没有答案