Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Network interface using UdpClient

$
0
0

Hello guys,

I'm working on a project and I need the following configuration :

device <-- wifi --> mobile <-- 4G --> Internet

The communication between the device and the mobile uses UDP protocol. I made an interface in PCL for UDP Client and I implemented it in my Android project as followed :

public class UdpClientDroid : IUdpClient  
{
    private UdpClient client = null;
    private IPEndPoint endPoint = null;

    public int Available { get { return client.Available; } }

    public void Connect(string hostname, int port)
    {
        if (this.client == null)
        {
            endPoint = new IPEndPoint(IPAddress.Parse(ViewModelLocator.Instance.HomeViewModel.WifiIP), port: port);
            this.client = new UdpClient(endPoint);
        }

        this.client.Connect(hostname, port);         
    }

    public byte[] Receive(int port)
    {
        IPEndPoint ep = new IPEndPoint(IPAddress.None, port);
        return this.client.Receive(ref ep);
    }

    public void Send(byte[] data)
    {
        this.client.Send(data, data.Length);
    }
}

Now my problem is I can't send or receive data from Wifi, even if client is correctly connected to my device. client.Available is always equal to 0.

Any idea or workarround to resolve that ?

Thx


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>