SignalR hub.on方法未在Android中触发

时间:2014-08-13 12:32:38

标签: android signalr

我试图在Android应用程序中实现SignalR客户端。但是hub.on(“方法名称”)没有被解雇。

Platform.loadPlatformComponent( new AndroidPlatformComponent() );
String host = "...";
String qs = "....";
HubConnection connection = new HubConnection(...);
HubProxy hub = connection.createHubProxy( ... );

我尝试过以下两个选项来订阅

选项1

hub.on( “testMessage”, new SubscriptionHandler1< CustomMessage >() {
    @Override
    public void run(CustomMessage msg) {

        Log.d(“result := “, msg.text);
        Toast.makeText(MainActivity.this, msg.text, Toast.LENGTH_LONG).show();
    }
}, CustomMessage.class);

选项2

....
hub.subscribe(“testMessage”);
....
Handler handler = new Handler();

public void addMessage( CustomMessage msg ) {

    final String fStatus = msg.text;
    handler.post(new Runnable(){

        @Override
        public void run() {

            Toast.makeText(MainActivity.this, fStatus, Toast.LENGTH_LONG).show()
        }
    });
}

我收到了跟踪记录消息

Verbose – serverSentEvents – Found new data:data: {}
Verbose – serverSentEvents – Trigger onData: {}
Verbose – HubConnection – Received data;

0 个答案:

没有答案