【发布时间】:2015-02-28 16:48:53
【问题描述】:
我是 android xamarin 的初学者。我想使用 SignalR 实时使用聊天室。但我不知道这个例子中的“http://10.0.2.2:8081/echo”是什么意思。它是服务器吗???该服务器中有一些东西 - 比如 php 文件、数据库或其他东西??? 希望您的回答,谢谢:D 或任何人告诉我如何构建群聊应用程序,请(使用套接字,如:http://www.androidhive.info/2014/10/android-building-group-chat-app-using-sockets-part-1/ 或 xamarin 中的 SignalR)
using System.Collections.Generic;
using Android.App;
using Android.OS;
using Android.Widget;
namespace SignalR.Client.MonoDroid.Sample
{
[Activity(Label = "SignalR.Client.MonoDroid.Sample", MainLauncher = true, Icon = "@drawable/icon")]
public class DemoActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var messageListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, new List<string>());
var messageList = FindViewById<ListView>(Resource.Id.Messages);
messageList.Adapter = messageListAdapter;
var connection = new Connection("http://10.0.2.2:8081/echo");
connection.Received += data =>
RunOnUiThread(() => messageListAdapter.Add(data));
var sendMessage = FindViewById<Button>(Resource.Id.SendMessage);
var message = FindViewById<TextView>(Resource.Id.Message);
sendMessage.Click += delegate
{
if (!string.IsNullOrWhiteSpace(message.Text) && connection.State == ConnectionState.Connected)
{
connection.Send("Android: " + message.Text);
RunOnUiThread(() => message.Text = "");
}
};
connection.Start().ContinueWith(task => connection.Send("Android: connected"));
}
}
}
【问题讨论】:
标签: android xamarin signalr chat