我正在尝试转换可以在 Mono for Android 中处理 TCP 服务器的代码。这是此聊天应用程序 for Windows 教程中的代码。但是,我收到错误:
ListenForClient 访问被拒绝!
它是由这部分代码创建的:
try
{
//We are using TCP sockets
serverSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
//Assign the any IP of the machine and listen on port number 1000
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 1000);
//Bind and listen on the given address
serverSocket.Bind(ipEndPoint);
serverSocket.Listen(4);
//Accept the incoming clients
serverSocket.BeginAccept(new AsyncCallback(OnAccept), null);
}
catch (Exception ex)
{
System.Console.WriteLine("@ ListenForClient" + ex.Message);
Android.Util.Log.Info("ListenForClient", ex.Message);
}
看起来serverSocket.Bind(IPEndPoint);
在 Mono for Android 中是不允许的。有人知道解决方法或知道为什么不允许这样做吗?