首先,我是安卓和dot42的新手。我构建了一个UDP侦听器类,它在Windows应用程序中运行良好。我正在使用System.Net.Sockets.UdpClient类。
现在,我尝试在dot42项目中使用UDP侦听器类,但是我得到了错误消息。
未找到System.Net.Sockets.UdpClient类型。
我想这个类在dot42中是不可用的?
有什么方法可以让我在Android应用程序中使用相同的代码(或者只是几处修改)呢?
using System;
using System.Net;
using System.Net.Sockets;
namespace FSInterface
{
public class UDPReceiver
{
private UdpClient _udpRx;
private IPEndPoint ep;
private int _port;
public delegate void BytesReceive(byte[] buffer);
public event BytesReceive OnBytesReceive;
public UDPReceiver(int port)
{
_port = port;
_udpRx = new UdpClient();
_udpRx.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
_udpRx.ExclusiveAddressUse = false;
ep = new IPEndPoint(IPAddress.Any, _port);
_udpRx.Client.Bind(ep);
_udpRx.BeginReceive(new AsyncCallback(ReceiveCallback), null);
}
private void ReceiveCallback(IAsyncResult ar)
{
_udpRx.BeginReceive(new AsyncCallback(ReceiveCallback), null);
byte[] buffer = _udpRx.EndReceive(ar, ref ep);
if (OnBytesReceive != null)
{
OnBytesReceive(buffer);
}
}
}
}发布于 2014-01-09 23:28:38
Dot42是一个很有前途的项目,仍然缺少的是更完整的一套BCL。
在这种情况下,您应该使用java类。您可以在java中找到许多客户端UDP代码的示例。如果希望在常规.net和dot42之间共享代码,则必须使用udp方法的接口,为常规.NET和Dot42提供单独的实现。
发布于 2014-03-11 11:24:09
有一点最新消息。我们在ApacheLicense2.0下发布了.NET实现。您现在可以自己添加缺失类型。https://github.com/dot42/api。
https://stackoverflow.com/questions/20984442
复制相似问题