我使用 Xamarin for Visual Studio 和 C# 语言编写了一个简单的应用程序。代码是:
HubConnection hubConnection;
IHubProxy chatHubProxy;
async void btnConnect_Click(object sender, EventArgs e)
{
try
{
TextView log = FindViewById<TextView>(Resource.Id.txtLog);
base.OnResume();
hubConnection = new HubConnection("http://192.168.1.3:2010/signalr");
chatHubProxy = hubConnection.CreateHubProxy("MyHub");
chatHubProxy.On<string>("AddMessage", (message) =>
{
TextView text = FindViewById<TextView>(Resource.Id.txtLog);
text.Text = message;
});
var localIP = "192.168.1.104"; //the android device has this IP
await hubConnection.Start();
var srvrMessage = chatHubProxy.Invoke<string>("LoginFromMobile", "mahdi", "p@SsW0Rd",
hubConnection.ConnectionId, localIP);
if (srvrMessage != null)
{
log.Text = srvrMessage.Result;
}
else
log.Text = "can't connect to …Run Code Online (Sandbox Code Playgroud)