public static async Task ConnectAsync(string hostName = HOST_NAME, string port = REMOTE_PORT)
        {
            if (!StubMode)
            {
#if WINDOWS_APP || WINDOWS_PHONE_APP
                // Set up the UDP connection.
                var droneIP = new HostName(hostName);

                udpSocket = new DatagramSocket();
                await udpSocket.BindServiceNameAsync(port);

                await udpSocket.ConnectAsync(droneIP, port);

                udpWriter = new DataWriter(udpSocket.OutputStream);

                udpWriter.WriteByte(1);
                await udpWriter.StoreAsync();
#else
                udpSocket = new UdpClient();
                udpSocket.Connect(hostName, int.Parse(port));

                byte[] datagram = new byte[1] {
                    1
                };
                await udpSocket.SendAsync(datagram, datagram.Length);
#endif
            }

            var loop = Task.Run(() => DroneLoop());
        }
예제 #2
0
        public FastConnection(string remotehost, int remoteport, IRTSessionInternal session) : base(remotehost, remoteport, session)
        {
#if __WINDOWS__
            client = new DatagramSocket();
            client.MessageReceived += OnSocketMessageReceived;

            Task t = Task.Run(() => {
                ConnectAsync().Wait();

                DoLogin();
            });

            session.Log("FastConnection", GameSparksRT.LogLevel.DEBUG, " local=" + endPoint.LocalHostName + " remote=" + remotehost + ":" + remoteport);
#else
            bool ipv6 = false;

            callback = new AsyncCallback(Recv);

            if (remoteEndPoint.AddressFamily == AddressFamily.InterNetworkV6)
            {
                try {
                    if (Socket.OSSupportsIPv6)
                    {
                        ipv6 = true;
                    }
                } catch (Exception e) {
                    Console.WriteLine("Socket.OSSupportsIPv6: " + e.ToString());
                }

                try {
                    if (Socket.SupportsIPv6)
                    {
                        ipv6 = true;
                    }
                } catch (Exception e) {
                    Console.WriteLine("Socket.SupportsIPv6: " + e.ToString());
                }
            }

            if (ipv6)
            {
                client = new UdpClient(AddressFamily.InterNetworkV6);

                Console.WriteLine("IPv6 on!");
            }
            else
            {
                client = new UdpClient(AddressFamily.InterNetwork);
            }

            client.Connect(remoteEndPoint);

            session.Log("FastConnection", GameSparksRT.LogLevel.DEBUG, " local=" + client.Client.LocalEndPoint + " remote=" + remotehost + ":" + remoteport);

            client.Client.BeginReceive(buffer, 0, GameSparksRT.MAX_UNRELIABLE_MESSAGE_SIZE_BYTES, 0, callback, null);

            DoLogin();
#endif
        }