public async void StartReceiveAsync()
        {
            isRun = true;
            while(isRun)
            {
                if(!isReceive)
                {
                    System.Diagnostics.Debug.WriteLine("Start Receive");
                    udpSocket = new Windows.Networking.Sockets.DatagramSocket();
                    udpSocket.MessageReceived += UdpSocket_MessageReceived;

                    Windows.Networking.HostName hostName = null;
                    IReadOnlyList<Windows.Networking.HostName> networkinfo = Windows.Networking.Connectivity.NetworkInformation.GetHostNames();
                    foreach (Windows.Networking.HostName h in networkinfo)
                    {
                        if (h.IPInformation != null)
                        {
                            Windows.Networking.Connectivity.IPInformation ipinfo = h.IPInformation;
                            if (h.RawName == IPAddr)
                            {
                                hostName = h;
                                break;
                            }
                        }
                    }
                    if (hostName != null)
                        await udpSocket.BindEndpointAsync(hostName, Port);
                    else
                        await udpSocket.BindServiceNameAsync(Port);
                    outstm = await udpSocket.GetOutputStreamAsync(new Windows.Networking.HostName("255.255.255.255"), "49002");
                    await outstm.FlushAsync();
                    Windows.Storage.Streams.DataWriter dw = new Windows.Storage.Streams.DataWriter(outstm);
                    dw.WriteString("Start Receive");
                    await dw.StoreAsync();
                    isReceive = true;
                }
                else
                {
                    if(CurrentStat.GPSStatus !=null & CurrentStat.ATTStatus != null)
                    {
                        if (onXPlaneStatReceived != null)
                            onXPlaneStatReceived.Invoke(this, CurrentStat);
                    }
                    System.Diagnostics.Debug.WriteLine("Try To Sleep");
                    isReceive = false;
                    await udpSocket.CancelIOAsync();
                    udpSocket.MessageReceived -= UdpSocket_MessageReceived;
                    udpSocket.Dispose();
                    udpSocket = null;
                }
                await Task.Delay(waitSeconds*1000);
            }
        }
Exemple #2
0
 public async Task Bind(string profile, int liveViewPort)
 {
     await socket.BindEndpointAsync(new HostName(profile), liveViewPort.ToString());
 }