SignalR in android

此生再无相见时 提交于 2019-12-13 03:30:34

问题


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);
        }
    }

来源:https://stackoverflow.com/questions/56652291/signalr-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!