Как я могу использовать SignalR в Android-студии. Я подключаюсь к серверу, который сделал .Net. Но когда я отправляю запрос. Это отключено. Я спросил 3 раза, но никто не респ. Помоги мне .
в .Net
public class MyHub : Hub
{
public async Task SendMessage(String user)
{
Console.WriteLine(user);
await Clients.All.SendAsync("ReceiveMessage", user);
}
}
В Android Studio.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Platform.loadPlatformComponent(new AndroidPlatformComponent());
textView =findViewById(R.id.textView);
hubConnection = HubConnectionBuilder.create("http://10.0.2.2:5000/chatHub").build();
hubConnection.on("ReceiveMessage",(user)->{
textView.setText(user);
},String.class);
hubConnection.start();
}
public void onClick(View v) {
user = "Nam";
if(hubConnection.getConnectionState()== HubConnectionState.CONNECTED){
hubConnection.send("SendMessage",user);
textView.setText("Sent");
}
}