SignalR in android

2019-08-30 08:09发布

问题:

I create signal and it not run. I want to click button in app 1 and app 2 textview set "Nam". But Click button in app 1. text view show connect. but app 2 is not set text 'Nam'. Click button on app 2. It show Nam. Signal in C# is correct. this is my code

    TextView textView;
    HubConnection hubConnection;
    String user ="Nam";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = findViewById(R.id.textView);

        hubConnection = HubConnectionBuilder.create("http://10.0.2.2:5000/chatHub").build();
        hubConnection.start();

        hubConnection.on("ReceiveMessage", (user) -> {
            textView.setText(user);
        }, String.class);

    }
    public void onClick(View v) {
        if(hubConnection.getConnectionState()== HubConnectionState.CONNECTED){
            textView.setText("Connect");
            hubConnection.send("SendMessage",user);
        }
    }