首先,我是Android和dot42的新手。我已经构建了一个UDP Listener类,它在Windows应用程序中运行良好。我正在使用System.Net.Sockets.UdpClient类。
现在,我尝试在dot42项目中使用我的UDP Listener类,但是我收到了错误消息
找不到类型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);
}
}
}
}
答案 0 :(得分:1)
Dot42是一个非常有希望的项目,仍然缺少的是更完整的BCL。
在这种情况下,您应该使用java类。您可以在java中找到许多客户端UDP代码的示例。如果要在常规.net和dot42之间共享代码,则必须使用udp方法的接口以及常规.NET和Dot42的单独实现。
答案 1 :(得分:1)
稍微更新一下。我们在Apache License 2.0下发布了.NET实现。您现在可以自己添加缺失的类型。 https://github.com/dot42/api