First off, I am new to Android and dot42. I have built a UDP Listener class, which is working fine in a Windows application. I am using the System.Net.Sockets.UdpClient class.
Now, I have tried to use my UDP Listener class in a dot42 project, but I get the error message
Type System.Net.Sockets.UdpClient not found.
I guess, this class is not available within dot42?
Is there a way I can use the same code below (or only a few modifications) for Android apps?
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);
}
}
}
}