示例#1
0
        public static async Task StartCommand()
        {
            // WORK AS CLIENT
            try
            {
                client = new Windows.Networking.Sockets.DatagramSocket();
                client.MessageReceived += ClientDatagramSocket_MessageReceived;
                //var hostName = new HostName(TelloIpAddress);
                await client.BindServiceNameAsync(CommandPortNumber);

                // await client.ConnectAsync(new HostName(TelloIpAddress), CommandPortNumber);
                var a = client.Information;
                // Init, and set the speed to the minimum
                await SendCommand("command");
                await SendCommand("speed 10");

                // await SendCommand("streamon");
                IsCommandReady = true;
            }
            catch (Exception ex)
            {
                Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult);
                Debug.WriteLine(webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message);
            }
        }
示例#2
0
        private async void StartClient()
        {
            try
            {
                // Create the DatagramSocket and establish a connection to the echo server.
                var clientDatagramSocket = new Windows.Networking.Sockets.DatagramSocket();

                clientDatagramSocket.MessageReceived += ClientDatagramSocket_MessageReceived;

                // The server hostname that we will be establishing a connection to. In this example, the server and client are in the same process.
                var hostName = new Windows.Networking.HostName("localhost");

                await clientDatagramSocket.BindServiceNameAsync("servername");



                // Send a request to the echo server.
                string request = "Hello, World!";
                using (var serverDatagramSocket = new Windows.Networking.Sockets.DatagramSocket())
                {
                    using (Stream outputStream = (await serverDatagramSocket.GetOutputStreamAsync(hostName, "3655")).AsStreamForWrite())
                    {
                        using (var streamWriter = new StreamWriter(outputStream))
                        {
                            //await streamWriter.WriteAsync();
                            await streamWriter.FlushAsync();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult);
            }
        }
示例#3
0
文件: UdpSocket.cs 项目: sk8tz/RSSDP
        private void BindSocket()
        {
            Task t;

            if (!String.IsNullOrEmpty(_LocalIPAddress))
            {
                Windows.Networking.HostName localIpInfo = GetLocalIPInfo();

                t = _Socket.BindServiceNameAsync(this._LocalPort.ToString(), localIpInfo.IPInformation.NetworkAdapter).AsTask();
            }
            else
            {
                t = _Socket.BindServiceNameAsync(this._LocalPort.ToString()).AsTask();
            }

            t.Wait();
        }
示例#4
0
        public async void get()
        {
            Windows.Networking.Sockets.DatagramSocket socket = new Windows.Networking.Sockets.DatagramSocket();

            socket.MessageReceived += Socket_MessageReceived;

            //You can use any port that is not currently in use already on the machine.
            string serverPort = "21777";

            //Bind the socket to the serverPort so that we can start listening for UDP messages from the UDP echo client.
            await socket.BindServiceNameAsync(serverPort);
        }
        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);
            }
        }
示例#6
0
文件: UdpSocket.cs 项目: noex/RSSDP
        public UwaUdpSocket(int localPort)
        {
            _DataAvailableSignal = new System.Threading.ManualResetEvent(false);
            _ReceivedData = new System.Collections.Concurrent.ConcurrentQueue<ReceivedUdpData>();

            this.localPort = localPort;

            _Socket = new Windows.Networking.Sockets.DatagramSocket();
            _Socket.MessageReceived += _Socket_MessageReceived;

            var t = _Socket.BindServiceNameAsync(this.localPort.ToString()).AsTask();
            t.Wait();
        }
示例#7
0
        public UwaUdpSocket(int localPort)
        {
            _DataAvailableSignal = new System.Threading.ManualResetEvent(false);
            _ReceivedData        = new System.Collections.Concurrent.ConcurrentQueue <ReceivedUdpData>();

            this.localPort = localPort;

            _Socket = new Windows.Networking.Sockets.DatagramSocket();
            _Socket.MessageReceived += _Socket_MessageReceived;

            var t = _Socket.BindServiceNameAsync(this.localPort.ToString()).AsTask();

            t.Wait();
        }
示例#8
0
文件: UdpSocket.cs 项目: noex/RSSDP
        public UwaUdpSocket(string ipAddress, int multicastTimeToLive, int localPort)
        {
            _DataAvailableSignal = new System.Threading.ManualResetEvent(false);
            _ReceivedData = new System.Collections.Concurrent.ConcurrentQueue<ReceivedUdpData>();

            this.ipAddress = ipAddress;
            this.multicastTimeToLive = multicastTimeToLive;
            this.localPort = localPort;

            _Socket = new Windows.Networking.Sockets.DatagramSocket();
            //_Socket.Control.MulticastOnly = true;
            _Socket.MessageReceived += _Socket_MessageReceived;
            var t = _Socket.BindServiceNameAsync(this.localPort.ToString()).AsTask();
            t.Wait();
            _Socket.JoinMulticastGroup(new Windows.Networking.HostName(Rssdp.Infrastructure.SsdpConstants.MulticastLocalAdminAddress));
        }
示例#9
0
        public UwaUdpSocket(string ipAddress, int multicastTimeToLive, int localPort)
        {
            _DataAvailableSignal = new System.Threading.ManualResetEvent(false);
            _ReceivedData        = new System.Collections.Concurrent.ConcurrentQueue <ReceivedUdpData>();

            this.ipAddress           = ipAddress;
            this.multicastTimeToLive = multicastTimeToLive;
            this.localPort           = localPort;

            _Socket = new Windows.Networking.Sockets.DatagramSocket();
            //_Socket.Control.MulticastOnly = true;
            _Socket.MessageReceived += _Socket_MessageReceived;
            var t = _Socket.BindServiceNameAsync(this.localPort.ToString()).AsTask();

            t.Wait();
            _Socket.JoinMulticastGroup(new Windows.Networking.HostName(Rssdp.Infrastructure.SsdpConstants.MulticastLocalAdminAddress));
        }
示例#10
0
        public async void StartServer()
        {
            try
            {
                var serverDatagramSocket = new Windows.Networking.Sockets.DatagramSocket();

                // The ConnectionReceived event is raised when connections are received.
                serverDatagramSocket.MessageReceived += ServerDatagramSocket_MessageReceived;

                // Start listening for incoming TCP connections on the specified port. You can specify any port that's not currently in use.
                await serverDatagramSocket.BindServiceNameAsync(ServerPortNumber);
            }
            catch (Exception ex)
            {
                Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult);
                Debug.WriteLine("failed to bind");
            }
        }
示例#11
0
        private async void StartClient()
        {
            try
            {
                // Create the DatagramSocket and establish a connection to the echo server.
                var clientDatagramSocket = new Windows.Networking.Sockets.DatagramSocket();

                clientDatagramSocket.MessageReceived += ClientDatagramSocket_MessageReceived;

                // The server hostname that we will be establishing a connection to. In this example, the server and client are in the same process.
                var hostName = new Windows.Networking.HostName("localhost");

                this.clientListBox.Items.Add("client is about to bind...");

                await clientDatagramSocket.BindServiceNameAsync(UDPSocketPage.ClientPortNumber);

                this.clientListBox.Items.Add(string.Format("client is bound to port number {0}", UDPSocketPage.ClientPortNumber));

                // Send a request to the echo server.
                string request = "Hello, World!";
                using (var serverDatagramSocket = new Windows.Networking.Sockets.DatagramSocket())
                {
                    using (Stream outputStream = (await serverDatagramSocket.GetOutputStreamAsync(hostName, UDPSocketPage.ServerPortNumber)).AsStreamForWrite())
                    {
                        using (var streamWriter = new StreamWriter(outputStream))
                        {
                            await streamWriter.WriteLineAsync(request);

                            await streamWriter.FlushAsync();
                        }
                    }
                }

                this.clientListBox.Items.Add(string.Format("client sent the request: \"{0}\"", request));
            }
            catch (Exception ex)
            {
                Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult);
                this.clientListBox.Items.Add(webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message);
            }
        }
示例#12
0
        private async void StartServer()
        {
            try
            {
                var serverDatagramSocket = new Windows.Networking.Sockets.DatagramSocket();

                // The ConnectionReceived event is raised when connections are received.
                serverDatagramSocket.MessageReceived += ServerDatagramSocket_MessageReceived;

                this.listbox_Logger.Items.Add("server is about to bind...");

                // Start listening for incoming TCP connections on the specified port. You can specify any port that's not currently in use.
                await serverDatagramSocket.BindServiceNameAsync(ServerPort);

                this.listbox_Logger.Items.Add(string.Format("server is bound to port number {0}", ServerPort));
            }
            catch (Exception ex)
            {
                Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult);
                this.listbox_Logger.Items.Add(webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message);
            }
        }
示例#13
0
        public static async Task StartStatus()
        {
            while (!IsCommandReady)
            {
                await Task.Delay(50);
            }
            // WORK AS SERVER
            try
            {
                // Initialize the UDP connect
                status = new Windows.Networking.Sockets.DatagramSocket();

                await status.BindServiceNameAsync(StatusPortNumber);

                // Called when new message arrived
                status.MessageReceived += ServerDatagramSocket_MessageReceived;
            }
            catch (Exception ex)
            {
                Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult);
                Debug.WriteLine(webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message);
            }
        }