我正在尝试转换可以在 Android 的 Mono 中处理 TCP 服务器的代码。这是来自 this chat app for Windows tutorial 的代码.但是,我收到错误:
ListenForClient Access Denied!
它是由这部分代码创建的:
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);
在 Android 的 Mono 中是不允许的。
有人知道解决方法或知道为什么不允许吗?
最佳答案
找到解决方案,是2个问题,
1) 安卓 list :
<uses-permission android:name="android.permission.INTERNET" />
2) 端口 1000 已保留!
关于sockets - Android Socket.bind 的 TCP 服务器单声道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10575283/